【发布时间】:2014-03-31 14:31:24
【问题描述】:
我已安装 Sonata Media Bundle,但我不使用该套件的图库部分。
如何禁用图库?
我使用的是 Symfony 2.3,并且按照文档安装了标准的 Media Bundle。
到目前为止的解决方案:
如果您从管理包中查看此问题 https://github.com/sonata-project/SonataAdminBundle/issues/460,您可以通过将 show_in_dashboard: false 标记添加到 yaml 文件来禁用管理员。
为此,我只需添加自己的编译器,然后为我添加此标志:
创建您的编译器:http://symfony.com/doc/current/components/dependency_injection/tags.html
将您的编译器添加到您的包中:http://symfony.com/doc/2.3/cookbook/service_container/compiler_passes.html
你就完成了。如果有更好的解决方案,我很乐意听到。
编译器示例:
namespace YourBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class OverrideMediaGalleryCompilerPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @api
*/
public function process( ContainerBuilder $container )
{
$definition = $container->getDefinition( 'sonata.media.admin.gallery' );
if ( $definition ) {
/**
* The purpose here is to disable the sonata admin gallery from showing up
* in the dashboard. This goes through and adds show_in_dashboard parameter
* that disables this.
*/
if ( $definition->hasTag( 'sonata.admin' ) ) {
$tags = $definition->getTag( 'sonata.admin' );
$tags[ 0 ][ 'show_in_dashboard' ] = false;
$definition->clearTag( 'sonata.admin' );
$definition->addTag( 'sonata.admin', $tags[ 0 ] );
}
}
}
}
【问题讨论】:
标签: symfony-sonata sonata-media-bundle