我安装了 Sonata Media Bundle,但我不使用该包的画廊部分。
如何禁用图库?
我正在使用 Symfony 2.3,并且按照文档安装了标准媒体包。
到目前为止的解决方案:
如果您从管理包中查看此问题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 ] );
}
}
}
}