form_field_definition.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Form field definition
  2. =====================
  3. These fields are used to display inside the edit form.
  4. Example
  5. -------
  6. .. code-block:: php
  7. <?php
  8. namespace Bundle\Sonta\NewsBundle\Admin;
  9. use Bundle\Sonata\BaseApplicationBundle\Admin\Admin;
  10. class PostAdmin extends Admin
  11. {
  12. protected $class = 'Application\Sonata\NewsBundle\Entity\Post';
  13. protected $formFields = array(
  14. 'enabled',
  15. 'title',
  16. 'abstract',
  17. 'content',
  18. 'tags' => array('options' => array('expanded' => true)),
  19. 'comments_close_at',
  20. 'comments_enabled',
  21. 'comments_default_status'
  22. );
  23. public function configureFormFields()
  24. {
  25. $this->formFields['comments_default_status']->setType('choice');
  26. $options = $this->formFields['comments_default_status']->getOption('form_field_options', array());
  27. $options['choices'] = Comment::getStatusList();
  28. $this->formFields['comments_default_status']->setOption('form_field_options', $options);
  29. }
  30. }
  31. Types available
  32. ---------------
  33. - array
  34. - boolean
  35. - choice
  36. - datetime
  37. - decimal
  38. - integer
  39. - many_to_many
  40. - many_to_one
  41. - one_to_one
  42. - string
  43. - text
  44. if no type is set, the Admin class will use the one set in the doctrine mapping definition.
  45. Tweak it!
  46. ---------
  47. - It is possible to tweak the default template by setting a template key in the
  48. - If the project required specific behaviors, they can be implemented in the
  49. configureFormFields() method.