Rectangle 27 0

You have to generate a new template which does the job.

->add('yourLink', null, array('template' => '::testfield.html.twig'))

Look into the SonataAdminBundle:Resource/CRUD/ folder where all list templates located.

In my case it works. But with the actions it's also good idea and it's smarter because you can add multiple custom links or buttons...

php - Add a Custom link in Listing Screen Sonata Admin Bundle - Stack ...

php symfony2 doctrine2 sonata-admin
Rectangle 27 0

I figured it out myself. You need to create a custom template and then add it as an action.

->add('_action', 'actions', array(
            'actions' => array(
                'floorplan' => array('template' => 'YourBundle:testLink.html.twig'),
            )
        ))

php - Add a Custom link in Listing Screen Sonata Admin Bundle - Stack ...

php symfony2 doctrine2 sonata-admin
Rectangle 27 0

Of course you can, as far as you return a Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery instance :

/**
     * {@inheritDoc}
     */
    public function createQuery($context = 'list')
    {
        $repository = $this->modelManager->getEntityManager($this->getClass())->getRepository($this->getClass());
        $query = new ProxyQuery($repository->createMyCustomQueryBuilder());

        foreach ($this->extensions as $extension) {
            $extension->configureQuery($this, $query, $context);
        }

        return $query;
    }

php - Sonata Admin Bundle custom query for list to use existing Reposi...

php symfony2 doctrine sonata-admin
Rectangle 27 0

You have to specifie that sizes is a collection , add 'sizes', 'collection'. This is working line SF2 form. Types can be found here, you'll found collections' attributes too: http://symfony.com/fr/doc/current/reference/forms/types.html

But the form to insert data works fine. I can mark some options (sizes) and save the new product. The exception occurs when I want show the stored products on database. Thanks for a quick answer :)

php - How to list objects with a simple array type field on a Symfony ...

php symfony2 sonata-admin
Rectangle 27 0

set two parameters baseRoutePattern and baseRouteName in your admin class

If helped you do fix your problem that mark the answer as correct.

php - Different lists for one model in sonata admin bundle - Stack Ove...

php symfony2 symfony-sonata
Rectangle 27 0

If you need to get the full path in controller (can happen, very rarely but can happen) you have to use the media service

$mm = $this->container->get('sonata.media.manager.media');
$pr = $this->container->get('sonata.media.provider.image');
$media = $mm->findOneBy(array('id' => $idImage));
$format = $pr->getFormatName($media, 'default');
$path = $pr->generatePublicUrl($media, $format);

or use the twig helper inside the controller

$format = 'default'; //the format you want to show
$path=$this->get('sonata.media.twig.extension')->path($image, $format);

if you want to add the image to the list field of Sonata Admin (your case) you can use this code

{% block field %}

        {% thumbnail object.image, 'thumb' %}

{% endblock %}

where image is the image getter method of your entity (es getImage() )

php - List Images in sonata admin bundle - Stack Overflow

php symfony2 sonata-admin
Rectangle 27 0

Unfortunately you can't. It is because the sonata admin has to build (or in your case) finishes the query (because of filtering, limiting, paging and so on..)

php - Sonata Admin Bundle custom query for list to use existing Reposi...

php symfony2 doctrine sonata-admin
Rectangle 27 0

Although the result is not beautiful. I've solved the problem just adding 'array' type to 'sizes' field on configureShowFields and configureListFields methods. The result shows sizes field like [0 => 38] [1 => 40] [2 => 42] [3 => 43] [4 => 45] [5 => 46] and I would like it as similar to 38, 40, 42, 43, 45, 46

/**
     * @param ListMapper $listMapper
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->add('id')                
            ->add('sizes', 'array') // I've just added array type
            ->add('_action', 'actions', array(
                'actions' => array(
                    'show' => array(),
                    'edit' => array(),
                    'delete' => array(),
                )
            ))
        ;
    }
    /**
     * @param ShowMapper $showMapper
     */
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            ->add('id')                
            ->add('sizes', 'array') // I've just added array type
        ;
    }

I would appreciate a better way. Thanks

php - How to list objects with a simple array type field on a Symfony ...

php symfony2 sonata-admin
Rectangle 27 0

I needed something similar and this is my result after a while of searching the internet.

I have added tbe template in the configureListFields method from the admin class:

->add('culture', "string", array(
            'template' => 'AEWBackendBundle:CRUD:list_culture_image.html.twig'
        ))

I have created the template in the view:

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
    <div>
        {% set flag = web_path ~ 'images/flags/' ~ object.culture.name(object) ~ '.png' %}
        {% if file_exists(flag) %}
            <img id="culture_image" title="{{ object.culture }}" src="/images/flags/{{ object.culture.name }}.png" height="15" />
        {% else %}
            <img id ="culture_image" title="en" src="/images/flags/default.png" height="15" />
        {% endif  %}
    </div>
{% endblock %}
web_path: %kernel.root_dir%/../web/
twig:
    globals:
        web_path: %web_path%

Created the TwigExtension.php file to use the file_exists PHP function as a twig extension

<?php

namespace AEW\FrontendBundle\Services\Extension;

use \Twig_Filter_Function;
use \Twig_Filter_Method;

class TwigExtension extends \Twig_Extension
{

    /**
     * Return the functions registered as twig extensions
     * 
     * @return array
     */
    public function getFunctions()
    {
        return array(
            'file_exists' => new \Twig_Function_Function('file_exists'),
        );
    }

    public function getName()
    {
        return 'twig_extension';
    }
}

Added the config lines in config.yml for the new extension:

parameters:
    aew.twig_extension.class: AEW\FrontendBundle\Services\Extension\TwigExtension

services:
    aew.twig_extension:
        class: %aew.twig_extension.class%
        tags:
            - { name: twig.extension }

Hope this helps you or anyone else who is looking for this info in the future.

php - How to get images listed in sonata admin bundle backend - Stack ...

php symfony2 doctrine2 doctrine sonata-admin
Rectangle 27 0

Then it's really straight forward to just use Sonata Admin as per the examples without any tweaks required to manage the two sets in different lists.

php - Different lists for one model in sonata admin bundle - Stack Ove...

php symfony2 symfony-sonata
Rectangle 27 0

The simplest way is to create custom admin field template. In configureListFields method add:

->add('path', null, array('template' => 'AcmeBundle:Admin:list_image.html.twig'))
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field%}
    <div>
        <img src="{{ object.webPath | imagine_filter('gallery_element_admin') }}" />
        {# or whatever to create src of image #}
    </div>
{% endblock %}

thank you.. i followed the same , but didn't work for me !!

what is the result / error?

i have updated the code, with your code, and i didn;t get any error, still i didn't get any picture there.

View page source, find image tag and check image src address (try to open) or <img> tag is missing? You should also notice {# #} is a commnet in twig.

extremely sorry , but as i am new to symfony even php, still not sure how to get make path in twig, can u please show me any stuff example. i am searching but unable to get any solution.

php - How to get images listed in sonata admin bundle backend - Stack ...

php symfony2 doctrine2 doctrine sonata-admin