gpt4 book ai didi

symfony-sonata - 奏鸣曲媒体包删除画廊

转载 作者:行者123 更新时间:2023-12-04 06:46:29 25 4
gpt4 key购买 nike

我安装了 Sonata Media Bundle,但我没有使用该 bundle 的图库部分。

如何禁用图库?

我使用的是 Symfony 2.3,并且根据文档安装了标准的 Media Bundle。

目前的解决方案:

如果你看这个问题https://github.com/sonata-project/SonataAdminBundle/issues/460从管理包中,您可以通过将 show_in_dashboard: false 标记添加到 yaml 文件来禁用管理员。

为此,我只需添加我自己的编译器,然后为我添加此标志:

  1. 创建你的编译器:http://symfony.com/doc/current/components/dependency_injection/tags.html

  2. 将您的编译器添加到您的包中: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 ] );
}
}
}
}

最佳答案

只需将以下服务配置添加到您的 config.ymlsonata_admin.yml 文件中即可禁用管理面板中的图库和媒体菜单或使用 services.yml 文件在 config 目录中,并从 dependencyInjection 类中加载它

#Application/Sonata/MediaBundle/DependencyInjection/ApplicationSonataMediaExtension.php
<?php

namespace Application\Sonata\MediaBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class ApplicationSonataMediaExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}

如果您只想删除图库菜单,请仅使用 sonata.media.admin.gallery: 服务

#Application/Sonata/MediaBundle/Resources/config/services.yml
#Disable gallery & media menu from admin panel
services:
sonata.media.admin.media:
class: %sonata.media.admin.media.class%
tags:
- { name: sonata.admin, manager_type: orm, show_in_dashboard: false, label_catalogue: %sonata.media.admin.media.translation_domain% , label_translator_strategy: sonata.admin.label.strategy.underscore }
arguments:
- ~
- %sonata.media.admin.media.entity%
- %sonata.media.admin.media.controller%
- "@sonata.media.pool"
calls:
- [setModelManager, ["@sonata.media.admin.media.manager"]]
- [setTranslationDomain, [%sonata.media.admin.media.translation_domain%]]
- [setTemplates, [{ inner_list_row: SonataMediaBundle:MediaAdmin:inner_row_media.html.twig , base_list_field: SonataAdminBundle:CRUD:base_list_flat_field.html.twig , list: SonataMediaBundle:MediaAdmin:list.html.twig , edit: SonataMediaBundle:MediaAdmin:edit.html.twig }]]

sonata.media.admin.gallery:
class: %sonata.media.admin.gallery.class%
tags:
- { name: sonata.admin, manager_type: orm, show_in_dashboard: false, label_catalogue: %sonata.media.admin.media.translation_domain% , label_translator_strategy: sonata.admin.label.strategy.underscore }
arguments:
- ~
- %sonata.media.admin.gallery.entity%
- %sonata.media.admin.gallery.controller%
- "@sonata.media.pool"
calls:
- [setTranslationDomain, [%sonata.media.admin.media.translation_domain%]]
- [setTemplates, [{ list: SonataMediaBundle:GalleryAdmin:list.html.twig }]]

然后清除缓存以反射(reflect)更改

php app/console cache:clear

关于symfony-sonata - 奏鸣曲媒体包删除画廊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22080760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com