Documentation » Admin

9. Form Help Messages and Descriptions »

« 7. Saving hooks

8. Form Types

8.2. Other form types

The bundle comes with some handy form types which are available from outside the scope of the SonataAdminBundle:

8.2.1. sonata_type_immutable_array

The Immutable Array allows you to edit an array property by defining a type per key.

The type has a keys parameter which contains the definition for each key. A definition is an array with 3 options :

  • key name
  • type : a type name or a FormType instance
  • related type parameters : please refer to the related form documentation.

Let’s say a Page have options property with some fixed key-pair values, each value has a different type : integer, url, or string for instance.

class Page
    protected $options = array(
        'ttl'       => 1,
        'redirect'  => ''

    public function setOptions(array $options)
        $this->options = $options;

    public function getOptions()
        return $this->options;

Now, the property can be edited by setting a type for each type

$form->add('options', 'sonata_type_immutable_array', array(
    'keys' => array(
        array('ttl',        'text', array('required' => false)),
        array('redirect',   'url',  array('required' => true)),

8.2.2. sonata_type_boolean

The boolean type is a specialized ChoiceType where the choices list is locked to ‘yes’ and ‘no’.

8.2.3. sonata_type_translatable_choice

Deprecated: use ChoiceType with the translation_domain option instead.

The translatable type is a specialized ChoiceType where the choices values are translated with the Symfony Translator component.

The type has one extra parameter :

  • catalogue : the catalogue name to translate the value

// The delivery list
class Delivery
    public static function getStatusList()
        return array(
            self::STATUS_OPEN      => 'status_open',
            self::STATUS_PENDING   => 'status_pending',
            self::STATUS_VALIDATED => 'status_validated',
            self::STATUS_CANCELLED => 'status_cancelled',
            self::STATUS_ERROR     => 'status_error',
            self::STATUS_STOPPED   => 'status_stopped',

// form usage
$form->add('deliveryStatus', 'sonata_type_translatable_choice', array(
    'choices' => Delivery::getStatusList(),
    'catalogue' => 'SonataOrderBundle'

8.3. Types options

8.3.1. General

  • label: You can set the label option to false if you don’t want to show it.
$form->add('status', null, array('label' => false);

Found a typo? Something is wrong in this documentation? Just fork and edit it!