Search code examples
symfonysonata-admin

How to retrieve subject in Sonata configureListFields not for action?


   protected function configureListFields(ListMapper $listMapper)
    {

        /** @var Article article */
        $article = $this->getSubject();

article is alyways null, i see How to retrieve subject in Sonata configureListFields?

but this solution put data to action - i need custom field (not mapped with thumb) i can do it easy if i getSubject();

I know that i can use template but creating template to get one var is strange concept


Solution

  • Maybe you should take a look at this bundle SonataExtraAdminBundle

    It provides some extra features for Sonata such as image type in list field, or string template.

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ...
            ->add('fullname', 'string_template', array(
                'string_template' => '<span class="pull-right">{{ object.firstname }} {{ object.lastname }}</span>'
            ))
        ;
    }