architecture.rst 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_fields``: The fields displayed in the list table;
  12. * ``filter_fields``: The fields available for filter the list;
  13. * ``form_fields``: The fields used to edit the entity;
  14. * The batch actions: Actions that can be performed on a group of entities
  15. (e.g. bulk delete)
  16. If a field is associated with another entity (and that entity also has an
  17. ``Admin`` class), then the related ``Admin`` class will be accessible from
  18. within the first ``Admin`` class.
  19. The admin class is ContainerAware, meaning that the entire dependency injection
  20. container is injected. Therefore, you have access to every service and can
  21. do things such as:
  22. * Access user permissions to define the list fields;
  23. * Access the ``Router`` to generate custom routes.
  24. Field Definition
  25. ----------------
  26. A field definition is an simple array. There is one definition per list
  27. field.
  28. The definition contains:
  29. * ``name``: The name of the field definition;
  30. * ``type``: The field type;
  31. * ``template``: The template to use to display the field;
  32. * ``targetEntity``: The class name of the target entity for relations;
  33. * ``options``: Certain field types have additional options;
  34. Template Configuration
  35. ~~~~~~~~~~~~~~~~~~~~~~
  36. The current implementation uses Twig as the template engine. All templates
  37. are located in the Resources/views/CRUD directory of the bundle. The base
  38. template extends two layouts:
  39. * ``BaseApplicationBundle::standard_layout.twig``
  40. * ``BaseApplicationBundle::ajax_layout.twig``
  41. Each field is rendered in three different ways and each has its own Twig
  42. template. For example, for a field with a ``text`` type, the following three
  43. templates will be used:
  44. * ``edit_text.twig``: template used in the form edition
  45. * ``filter_text.twig``: template used in the filter box
  46. * ``list_text.twig``: template used in the list table
  47. CrudController
  48. --------------
  49. The controller contains the basic CRUD actions, the controller is
  50. related to one ``Admin`` class by mapping the controller name to the correct
  51. ``Admin`` instance.
  52. All actions can be easily overwritten depending on the project's requirements.
  53. The controller uses the ``Admin`` class to construct the different actions.
  54. Inside the controller, the ``Admin`` object is accessible through the ``configuration``
  55. property.
  56. Obtaining an ``Admin`` Service
  57. ------------------------------
  58. ``Admin`` definition are accessible through the 'base_application.pool' service.
  59. The ``Admin`` definitions are lazy loaded from the Pool to avoid overhead.
  60. Filter and Datagrid
  61. -------------------
  62. todo ...
  63. .. _`Django Project Website`: http://www.djangoproject.com/