Search code examples
sonata-adminsymfony-3.3

Option usage configureListFields in SonataAdminBundle


unfortunately documentation doesn't cover how to use options available in configureListFields ListMapper when you add fields to the list.

This is my basic code

$listMapper
    ->add('myField', null, array(
        'label' => LabelHelper::LABEL_MY_FIELD,
        'code' => // what should I put here ... $this->methodName() is not working
    ))

I want to use 'code' option (docs - section 7.2.1), because I would like to customize just one filed final display. I don't want to rewrite the row template.

As stated in the code section I've tried simple method that returns string, but nothing happened in the list view (I've cleared cache etc.).


Solution

  • Answer is simple. You just put method name without brackets

    $listMapper
    ->add('myField', null, array(
        'label' => LabelHelper::LABEL_MY_FIELD,
        'code' => 'methodName'
    ))
    

    Method should be stored in corresponding Entity class