action_create_edit.rst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Creating and Editing objects
  2. ============================
  3. .. note::
  4. This document is a stub representing a new work in progress. If you're reading
  5. this you can help contribute, **no matter what your experience level with Sonata
  6. is**. Check out the `issues on Github`_ for more information about how to get involved.
  7. This document will cover the Create and Edit actions. It will cover configuration
  8. of the fields and forms available in these views and any other relevant settings.
  9. Basic configuration
  10. -------------------
  11. .. note::
  12. **TODO**:
  13. * global (yml) options that affect the create and edit actions
  14. * a note about Routes and how disabling them disables the related action
  15. * using configureFormFields() to set which fields to display
  16. * options available when adding fields, inc custom templates
  17. * link to the field_types document for more details about specific field types
  18. FormGroup options
  19. ~~~~~~~~~~~~~~~~~
  20. When adding a form group to your edit/create form, you may specify some options for the group itself.
  21. - ``collapsed``: unused at the moment
  22. - ``class``: the class for your form group in the admin; by default, the value is set to ``col-md-12``.
  23. - ``fields``: the fields in your form group (you should NOT override this unless you know what you're doing).
  24. - ``box_class``: the class for your form group box in the admin; by default, the value is set to ``box box-primary``.
  25. - ``description``: to complete
  26. - ``translation_domain``: to complete
  27. To specify options, do as follows:
  28. .. code-block:: php
  29. <?php
  30. // src/AppBundle/Admin/PersonAdmin.php
  31. class PersonAdmin extends Admin
  32. {
  33. // ...
  34. public function configureFormFields(FormMapper $formMapper)
  35. {
  36. $formMapper
  37. ->tab('General') // the tab call is optional
  38. ->with('Addresses', array(
  39. 'class' => 'col-md-8',
  40. 'box_class' => 'box box-solid box-danger',
  41. 'description' => 'Lorem ipsum',
  42. // ...
  43. ))
  44. ->add('title')
  45. // ...
  46. ->end()
  47. ->end()
  48. ;
  49. }
  50. Here is an example of what you can do with customizing the box_class on a group
  51. .. figure:: ../images/box_class.png
  52. :align: center
  53. :alt: Box Class
  54. :width: 500
  55. Embedding other Admins
  56. ----------------------
  57. .. note::
  58. **TODO**:
  59. * how to embed one Admin in another (1:1, 1:M, M:M)
  60. * how to access the right object(s) from the embedded Admin's code
  61. Customizing just one of the actions
  62. -----------------------------------
  63. .. note::
  64. **TODO**:
  65. * how to create settings/fields that appear on just one of the create/edit views
  66. * and any controller changes needed to manage them
  67. .. _`issues on GitHub`: https://github.com/sonata-project/SonataAdminBundle/issues/1519