Modifying the sonata.media.provider.image edit block / template

1,058 views
Skip to first unread message

Larry Williamson

unread,
Jan 16, 2013, 3:28:45 PM1/16/13
to sonata...@googlegroups.com
Trying to figure out what file I need to create or modify to implement an inline preview for oneToOne "image" field with a targetEntity of "Application\Sonata\MediaBundle\Entity\Media" while using the sonata.media.provider.image provider...

I found this: https://gist.github.com/1896431 -- which I think I can modify for images, but I don't know where I should put and configure the twig?

Are there separate twigs for edit/list/show for different types? 

Thanks in advance!

Larry Williamson

unread,
Jan 16, 2013, 7:17:50 PM1/16/13
to sonata...@googlegroups.com
OK, so I've gotten so far as creating a new provider class (ImagexProvider) in my bundle, just trying to figure out how to change the template for rendering the item in edit mode. Do I need to modify something associated with dataClass/type -- "file"?

Form Mapper call:

$formMapper
            ->with('General')
            ->add('name')
            ->add('subhead')
            ->end()
            ->with('Images')
            ->add('image', 'sonata_media_type',
                array(
                    'required' => false,
                    'by_reference' => false,
                    'compound' => true,
                    'provider' => 'barkerdzp.media.provider.imagex'
                )
            );


Provider definition:

<service id="my.media.provider.imagex" class="my\MediaBundle\Provider\ImagexProvider">
            <tag name="sonata.media.provider"/>
            <argument>my.media.provider.imagex</argument>
            <argument type="service" id="sonata.media.filesystem.local"/>
            <argument type="service" id="sonata.media.cdn.server"/>
            <argument type="service" id="sonata.media.generator.default"/>
            <argument type="service" id="sonata.media.thumbnail.format"/>
            <argument type="collection">
                <argument>jpg</argument>
                <argument>png</argument>
            </argument>
            <argument type="collection" />
            <argument type="service" id="sonata.media.adapter.image.gd"/>
            <call method="setTemplates">
                <argument type="collection">
                    <argument key='helper_thumbnail'>myMediaBundle:Provider:thumbnail.html.twig</argument>
                    <argument key='helper_view'>myMediaBundle:Provider:view_image.html.twig</argument>
                </argument>
            </call>
            <call method="setResizer">
                <argument type="service" id="sonata.media.resizer.simple"/>
            </call>
        </service>

Larry Williamson

unread,
Jan 16, 2013, 8:30:02 PM1/16/13
to sonata...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages