form_field_definition.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Sonta\NewsBundle\Admin;
  9. use Sonata\AdminBundle\Form\FormMapper;
  10. use Sonata\AdminBundle\Admin\Admin;
  11. class PostAdmin extends Admin
  12. {
  13. protected $form = array(
  14. 'author' => array('edit' => 'list'),
  15. 'enabled',
  16. 'title',
  17. 'abstract',
  18. 'content',
  19. 'tags' => array('form_field_options' => array('expanded' => true)),
  20. 'comments_close_at',
  21. 'comments_enabled',
  22. 'comments_default_status'
  23. );
  24. public function configureFormFields(FormMapper $form)
  25. {
  26. $form->add('author', array(), array('edit' => 'list'));
  27. $form->add('title');
  28. // add comments_default_status by configuring an internal FieldDescription
  29. $form->add('comments_default_status', array('choices' => Comment::getStatusList()), array('type' => 'choice'));
  30. // or by creating the FormField
  31. $form->add(new \Symfony\Component\Form\ChoiceField('comments_default_status', array('choices' => Comment::getStatusList())));
  32. }
  33. }
  34. Types available
  35. ---------------
  36. - array
  37. - boolean
  38. - choice
  39. - datetime
  40. - decimal
  41. - integer
  42. - many_to_many
  43. - many_to_one
  44. - one_to_one
  45. - string
  46. - text
  47. if no type is set, the Admin class will use the one set in the doctrine mapping definition.
  48. Tweak it!
  49. ---------
  50. - It is possible to tweak the default template by setting a template key in the
  51. - If the project required specific behaviors, they can be implemented in the
  52. configureFormFields() method.