4

谁能告诉我如何扩展和覆盖所有奏鸣曲媒体捆绑功能?我正在使用 Symfony2.3.​​3 和 Sonata Master Bundle 。

我看到了这个文档http://sonata-project.org/bundles/media/master/doc/index.html并且我知道一些基本的东西,比如:如何编写自定义提供程序、翻译器等等。安装后基本的东西可以工作,但是我不知道 。

我正在寻找将 BaseMediaBundle 覆盖为自定义,例如函数“configureListFields”。

我已经覆盖了这个包的控制器,但不是 BaseMediaAdmin。

此代码的问题是我的仪表板中的实体“媒体”消失了!

//在我的 services.xml 中:

<service id="sonata.media.admin.media" class="Application\Sonata\MediaBundle\Admin\MediaAdmin">
    <tag name="sonata.media.admin" manager_type="orm" group="Gestion des médias"
        label="Média" />
    <argument />
    <argument>Application\Sonata\MediaBundle\Entity\Media</argument>
    <argument>Application\SonataMediaBundle:MediaAdmin</argument>
    <call method="setTranslationDomain">
        <argument>SonataMediaBundle</argument>
    </call>
</service> 

//在我的应用程序\奏鸣曲\MediaBundle\Admin\MediaAdmin

namespace Application\Sonata\MediaBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\MediaBundle\Provider\Pool;
use Sonata\MediaBundle\Form\DataTransformer\ProviderDataTransformer;

use Knp\Menu\ItemInterface as MenuItemInterface;

use Sonata\MediaBundle\Admin\BaseMediaAdmin as BaseMediaAdmin;


class MediaAdmin extends BaseMediaAdmin
{

/**
 * {@inheritdoc}
 */
protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->add('custom', 'string', array('template' =>  'SonataMediaBundle:MediaAdmin:list_custom.html.twig'))
        ->add('enabled', 'boolean', array('editable' => true))
        ->add('_action', 'actions', array(
            'actions' => array(
                'view' => array(),
                'edit' => array(),
                'delete' => array(),
            )
        ))
    ;
}

}

有人问同样的问题:https ://groups.google.com/forum/#!topic/sonata-users/l3D_Vrd0Hm4

我谷歌它但没有找到。有人知道吗?

谢谢!

4

2 回答 2

7

您必须覆盖 %sonata.media.admin.media.class%

YourSite/MediaBundle/Ressource/config/services.yml

`

parameters:
    sonata.media.admin.media.class: YourSite\MediaBundle\Admin\MediaAdmin

services:
    custom_name.admin.media:
        class: %sonata.media.admin.media.class%
        arguments:
            - ~
            - YourSite\MediaBundle\Entity\Media
            - YourSiteMediaBundle:MediaAdmin
            - @sonata.media.pool
        tags:
            - {name: sonata.admin, manager_type: orm, group: admin, label: Médias}

`

在你的app/config/config.yml

imports:
/** ... **/
- { resource: @YourSiteMediaBundle/Resources/config/services.yml }


sonata_admin:
/** ... **/
dashboard:
    groups:
        /** ... **/
        Médias:
            items:
                - custom_name.admin.media
#               - sonata.media.admin.media
于 2014-01-22T14:09:17.080 回答
1

只需进行一些更改,您就可以重新声明服务sonata.media.admin.media ,

如下,这将有助于您自定义奏鸣曲媒体包的所有方式(控制器,管理员,甚至您可以覆盖模板)

此服务声明选自 sonata-project/media-bundle/Resources/config/doctrine_orm_admin.xml

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
    <parameter key="sonata.media.admin.media.class">Application\Sonata\MediaBundle\Admin\MediaAdmin</parameter>
</parameters>
<services>
    <service id="sonata.media.admin.media" class="%sonata.media.admin.media.class%" public="true">
    <tag name="sonata.admin" manager_type="orm" group="%sonata.media.admin.groupname%" label_catalogue="%sonata.media.admin.media.translation_domain%" label="media" label_translator_strategy="sonata.admin.label.strategy.underscore" icon="%sonata.media.admin.groupicon%"/>
    <argument/>
    <argument>%sonata.media.admin.media.entity%</argument>
    <argument>%sonata.media.admin.media.controller%</argument>
    <argument type="service" id="sonata.media.pool"/>
    <argument type="service" id="sonata.media.manager.category" on-invalid="null"/>
    <call method="setModelManager">
        <argument type="service" id="sonata.media.admin.media.manager"/>
    </call>
    <call method="setTranslationDomain">
        <argument>%sonata.media.admin.media.translation_domain%</argument>
    </call>
    <call method="setTemplates">
        <argument type="collection">
            <argument key="inner_list_row">@SonataMedia/MediaAdmin/inner_row_media.html.twig</argument>
            <argument key="outer_list_rows_mosaic">@SonataMedia/MediaAdmin/list_outer_rows_mosaic.html.twig</argument>
            <argument key="base_list_field">@SonataAdmin/CRUD/base_list_flat_field.html.twig</argument>
            <argument key="list">@SonataMedia/MediaAdmin/list.html.twig</argument>
            <argument key="edit">@SonataMedia/MediaAdmin/edit.html.twig</argument>
        </argument>
    </call>
</service>

将此服务导入 config.yml

imports:
    - { resource: "@ApplicationSonataMediaBundle/Resources/config/service.xml" }

你的管理类

namespace Application\Sonata\MediaBundle\Admin;

use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter;
use Sonata\MediaBundle\Admin\ORM\MediaAdmin as MediaBaseAdmin;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class MediaAdmin extends MediaBaseAdmin
{
    ...

    /**
     * {@inheritdoc}
     */
    public function configureListFields(ListMapper $listMapper)
    {
        // parent::configureListFields($listMapper);
    }

    /**
     * {@inheritdoc}
     */
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
           //
    }

}
于 2018-10-25T13:31:12.260 回答