Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata Media Bundle Override

Can any one tell me How I can extends and Override all sonata Media Bundle functionality ? I am using Symfony2.3.3 and Sonata Master Bundle .

I see this documentation http://sonata-project.org/bundles/media/master/doc/index.html and I know basic things like : How can write custom provider, translator and etc..basic things are working after installations but I do not know .

I am looking for to override the BaseMediaBundle to custom for exemple the function "configureListFields".

I already override the controller of this bundle, but not the BaseMediaAdmin.

The problem with this code is the entity "Media" disapear of my dashboard !

//In my 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> 

//In my 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(),
            )
        ))
    ;
}

}

same question ask by some one: https://groups.google.com/forum/#!topic/sonata-users/l3D_Vrd0Hm4

I Google It but nothing found. Any one know ?

Thanks!

like image 908
Kunwar Siddharth Singh Avatar asked Feb 15 '23 23:02

Kunwar Siddharth Singh


1 Answers

you must override %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}

`

and in your 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
like image 179
Sinelc Avatar answered Feb 23 '23 05:02

Sinelc