Symfony2 Sonata Admin show attribute only as a readyonly text Symfony2 Sonata Admin show attribute only as a readyonly text symfony symfony

Symfony2 Sonata Admin show attribute only as a readyonly text


$formMapper    ->add('post', 'entity',         array(            'label' => 'Some post',            'read_only' => true,            'disabled'  => true,            'class' => 'Acme\DemoBundle\Entity\Post'        )    );


This answer tells how to customize list rendering. Maybe the same approach works with form rendering?

If not, then you can create your custom form type according to create custom field type documentation, and customizing the template.


This is a bit old but this might help someone.

Here is the code that resolves your issue.

$formMapper->add('post', 'entity', array('label' => 'Some post','attr' => array(                    'readonly' => 'readonly',                    'disabled' => 'disabled',                ),                'class' => 'Acme\DemoBundle\Entity\Post'))