You are here

protected function FormModesSubscriber::addFormModesRoutes in Form mode manager 8.2

Same name and namespace in other branches
  1. 8 src/Routing/EventSubscriber/FormModesSubscriber.php \Drupal\form_mode_manager\Routing\EventSubscriber\FormModesSubscriber::addFormModesRoutes()

Add a collection of route per form mode for current entity.

Each entity need to define a collection of routes to be used by Drupal. Each `entity operation` is a form handler present for all, ContentEntityType plugins. Each operation represent a Form to be, displayed by formBuilder service in routes controllers. To respect core logic implemented by Drupal we need to add, a route for each operations (add/edit/add_page/admin_add) dynamically and, a transverse controller compatible to use form modes.

Each routes generated by `setFormModeCollection` and, `setAddPageCollection` respect the following naming, `ENTITY_ROUTES_BASIS.FORM_MODE_NAME` eg for Node entity :

$routes = [
  'add_form' => 'node.add.FORM_MODE_NAME',
  'edit_form' => 'entity.node.edit_form.FORM_MODE_NAME',
  'add_page' => 'form_mode_manager.node.add_page.FORM_MODE_NAME',
  'admin_add' => 'node.add.FORM_MODE_NAME',
];

Parameters

array $form_modes: All form-modes available for specified entity_type_id.

1 call to FormModesSubscriber::addFormModesRoutes()
FormModesSubscriber::alterRoutes in src/Routing/EventSubscriber/FormModesSubscriber.php
Add one route collection per entity using form modes.

File

src/Routing/EventSubscriber/FormModesSubscriber.php, line 145

Class

FormModesSubscriber
Listens to the dynamic route event and add routes using form modes.

Namespace

Drupal\form_mode_manager\Routing\EventSubscriber

Code

protected function addFormModesRoutes(array $form_modes) {
  foreach ($form_modes as $form_mode_infos) {
    $this
      ->setFormModeCollection($form_mode_infos, 'add_form');
    $this
      ->setFormModeCollection($form_mode_infos, 'edit_form');
    $this
      ->setFormModeCollection($form_mode_infos, 'admin_add');
    if (!empty($this->entityDefinition
      ->getKey('bundle'))) {
      $this
        ->setAddPageCollection($form_mode_infos);
    }
  }
}