architecture.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Architecture
  2. ============
  3. The architecture of the bundle is mostly based off of the Django Admin Project,
  4. which is a truly great project. More information can be found at the
  5. `Django Project Website`_.
  6. The Admin Class
  7. ---------------
  8. The ``Admin`` class is the CRUD definition of one Doctrine entity. It contains
  9. all the configuration necessary to display a rich CRUD for the entity. From
  10. within an admin class, the following information can be defined:
  11. * ``list``: The fields displayed in the list table;
  12. * ``filter``: The fields available for filter the list;
  13. * ``form``: The fields used to edit the entity;
  14. * ``formGroups``: The group definition where a field must be displayed (edit form)
  15. * The batch actions: Actions that can be performed on a group of entities
  16. (e.g. bulk delete)
  17. If a field is associated with another entity (and that entity also has an
  18. ``Admin`` class), then the related ``Admin`` class will be accessible from
  19. within the first ``Admin`` class.
  20. The admin class is a service implementing the ``AdminInterface``, meaning that
  21. only required dependencies are injected:
  22. * ``ListBuilder``
  23. * ``FormBuildre``
  24. * ``DatagridBuilder``
  25. * ``Router``
  26. * ``Request``
  27. * ``EntityManager``
  28. * ``Translator``
  29. Therefore, you have access to every service you want by injecting them into the
  30. admin class, like:
  31. .. code-block:: xml
  32. <service id="sonata.news.admin.post" class="%sonata.news.admin.post.class%">
  33. <tag name="sonata.admin" manager_type="orm" group="sonata_blog" label="post"/>
  34. <argument>%sonata.news.admin.post.entity%</argument>
  35. <argument>%sonata.news.admin.post.controller%</argument>
  36. <call method="setUserManager">
  37. <argument type="service" id="fos_user.user_manager" />
  38. </call>
  39. </service>
  40. Here, the FOS' User Manager is injected into the Post service.
  41. Field Definition
  42. ----------------
  43. A field definition is a FieldDescription object. There is one definition per list
  44. field.
  45. The definition contains:
  46. * ``name``: The name of the field definition;
  47. * ``type``: The field type;
  48. * ``template``: The template to use to display the field;
  49. * ``targetEntity``: The class name of the target entity for relations;
  50. * ``options``: Certain field types have additional options;
  51. Template Configuration
  52. ~~~~~~~~~~~~~~~~~~~~~~
  53. The current implementation uses Twig as the template engine. All templates
  54. are located in the Resources/views/CRUD directory of the bundle. The base
  55. template extends two layouts:
  56. * ``AdminBundle::standard_layout.twig``
  57. * ``AdminBundle::ajax_layout.twig``
  58. Each field is rendered in three different ways and each has its own Twig
  59. template. For example, for a field with a ``text`` type, the following three
  60. templates will be used:
  61. * ``edit_text.twig``: template used in the form edition
  62. * ``filter_text.twig``: template used in the filter box
  63. * ``list_text.twig``: template used in the list table
  64. CrudController
  65. --------------
  66. The controller contains the basic CRUD actions, the controller is
  67. related to one ``Admin`` class by mapping the controller name to the correct
  68. ``Admin`` instance.
  69. All actions can be easily overwritten depending on the project's requirements.
  70. The controller uses the ``Admin`` class to construct the different actions.
  71. Inside the controller, the ``Admin`` object is accessible through the ``configuration``
  72. property.
  73. Obtaining an ``Admin`` Service
  74. ------------------------------
  75. ``Admin`` definition are accessible through the 'sonata_admin.pool' service or directly from the DIC.
  76. The ``Admin`` definitions are lazy loaded from the DIC to avoid overhead.
  77. Filter and Datagrid
  78. -------------------
  79. todo ...
  80. .. _`Django Project Website`: http://www.djangoproject.com/