Sonata Media Bundle Override

时间:2013-10-17 07:25:45

标签: symfony sonata-admin symfony-sonata

任何人都可以告诉我如何扩展和覆盖所有奏鸣曲媒体包功能? 我正在使用Symfony2.3.​​3和Sonata Master Bundle。

我看到此文档http://sonata-project.org/bundles/media/master/doc/index.html和 我知道基本的东西:如何编写自定义提供程序,翻译器等。基本的东西在安装后工作但我不知道。

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

我已经覆盖了此捆绑包的控制器,但没有覆盖BaseMediaAdmin。

此代码的问题是我的信息中心实体“Media”消失了!

//在我的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> 

//在我的Application \ Sonata \ 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

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

谢谢!

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

只需更改几下,您就可以重新声明服务 sonata.media.admin.media

如下所示,这将有助于您自定义Sonata-Media-Bundle的所有方式(控制器,管理员,甚至您可以覆盖模板)

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

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

    

将此服务导入config.yml

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)
    {
           //
    }

}

您的管理员班

email