Skip to content

Instantly share code, notes, and snippets.

@a-r-m-i-n
Last active May 27, 2020 13:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-r-m-i-n/d5cfd73f4f0ca9b20353747cdabeba0e to your computer and use it in GitHub Desktop.
Save a-r-m-i-n/d5cfd73f4f0ca9b20353747cdabeba0e to your computer and use it in GitHub Desktop.
This document describes the process of Symfony's Easy Admin Bundle, to process the given YAML configuration, with registered **ConfigPass** classes.

Easy Admin Bundle ConfigPass

This document describes the process of Symfony's Easy Admin Bundle, to process the given YAML configuration, with registered ConfigPass classes.

The problem

Those ConfigPasses are collections of private methods, which have e.g. action names hardcoded, so you can't reuse the "config auto-magic" for your new actions.

My goal

Make ConfigPasses more accessible and reusable. Make it easier to e.g. provide new actions, which also inherit from "form" config and get normalized with default values.

Registered ConfigPasses

The config passes are registered and get executed in the following order:

1. NormalizerConfigPass

Each step iterates over configured entities.

  • normalizeEntityConfig:
    • Apply label or label is not set, apply the entity name as label
  • normalizeViewConfig:
    • Applies list.dql_filter to search.dql_filter or set both to null
    • Merges views ['edit', 'form', 'list', 'new', 'search', 'show'] (hardcoded!) with default config
  • normalizePropertyConfig:
    • Process fields in views ['form', 'edit', 'list', 'new', 'search', 'show'] (hardcoded!)
      • check if field is string or array
        • if is array check if property is set, throws exception if not
        • if is string create array with property set with string value
      • check if type in field is image (set base_path to image_base_path then)
      • check if type in field is file (set base_path to file_base_path then)
      • set field name to property, or if property is null, apply _easyadmin_form_design_element_ with iterator as field name
  • normalizeFormDesignConfig:
    • Process fields in views ['form', 'edit', 'new'] (hardcoded!)
      • check if field is "formDesignElement" (property=null, type set)
      • check for tab first, later also for group, divider and section
  • normalizeActionConfig:
    • First, processes the views ['edit', 'list', 'new', 'show', 'form'] (hardcoded!) and set actions in each view to empty array, if not given.
    • Then iterates over entities and does the same there (in actions). If actions is set, but no array, an exception is thrown
  • normalizeBatchActionConfig:
    • Initializes list.batch_actions (empty array) if not set
    • Does the same for batch_actions in each entity
    • Throws exception if batch_actions is given, but no array
  • normalizeFormConfig:
    • Merges form with new and edit
      • During merge, fields with prefixed '-' get removed
  • normalizeControllerConfig:
    • Checks for given controller (in each entity)
  • normalizeTranslationConfig:
    • Set translation_domain for each entity to root translation_domain config value if not set.

2. DesignConfigPass

  • processRtlLanguages:
    • When root locale is one of these ['ar', 'fa', 'he'], set design.rtl to true

3. MenuConfigPass

  • builds menu defined in design.menu

4. ActionConfigPass

  • processDisabledActions
    • applies root disabled_actions to each entity, if not set
  • normalizeActionsConfig
    • for hardcoded! views ['edit', 'list', 'new', 'show']
    • set label if empty
    • applies default values to each config
    • first all this apply to configured actions on root level. Then it's applied to actions of each entity.
  • normalizeBatchActionsConfig
    • normalizes list.batch_actions config
      • set btn-danger css class when deleted is given
    • does the same for each entity (entities.example.list.batch_actions)
  • resolveActionInheritance
    • for hardcoded! views ['edit', 'list', 'new', 'show']
    • merges actions in each entity with defined default, backend and entity actions
    • removes actions configured with '-'
    • reorders actions
  • resolveBatchActionInheritance
    • same like resolveActionInheritance
    • just for list.batch_actions in each entity
  • processActionsConfig
    • for hardcoded! views ['edit', 'list', 'new', 'show']
    • checks each action in each entity, if is valid method name and apply css_class "action-example"
  • processBatchActionsConfig
    • resolves list.batch_actions in each entity
    • checks if type is "method" (which is required for batch actions)
    • and check for valid method name

5. MetadataConfigPass

  • set properties based on given entities and Doctrine metadata.
  • also set primary_key_field_name

6. PropertyConfigPass

  • processMetadataConfig
    • guesses types and default options in each item in entities based on its properties
  • processFieldConfig
    • just for actions ['edit', 'list', 'new', 'search', 'show']
    • check for virtual properties
    • set dataType to type (for actions ['list', 'search', 'show'])
    • set fieldType to $originalFieldConfig['type'] or $normalizedConfig['fieldType'] (for actions ['list', 'search', 'show'])
    • set fieldType to textarea when still empty
    • set type_options (merges doctrine metadata with own configuration)
    • set format if empty (\EasyCorp\Bundle\EasyAdminBundle\Configuration\PropertyConfigPass::getFieldFormat)
    • in list action, when dataType is "boolean", change dataType to "toggle", if it wasn't configured in original field config

7. ViewConfigPass

  • all limited to actions ['edit', 'list', 'new', 'search', 'show']
  • processViewConfig
  • processDefaultFieldsConfig
  • processFieldConfig
  • processPageTitleConfig
  • processMaxResultsConfig (only in ['list', 'search', 'show'] actions)
  • processSortingConfig (only in ['list', 'search'] actions)

8. TemplateConfigPass

  • processEntityTemplates
    • resolve (first) template from configured paths (entities.example.templates -> design.templates -> default)
    • for ['list', 'show'] actions also apply custom template for each field (if given)
  • processDefaultTemplates
    • resolve (first) template from design.templates and default paths
  • processFieldTemplates
    • just in ['list', 'show'] actions
    • assignes templates to each field (e.g. hides primary key field by using template "field_id")

9. DefaultConfigPass

  • processDefaultEntity
    • set default_entity_name to first entity in yaml config
  • processDefaultMenuItem
    • set default_menu_item to first item with default: true
  • processDefaultHomepage
    • set homepage to default menu item, if given
    • otherwise route to list action of first configured entity in yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment