You are here

public function FormModesSubscriber::getFormModeListPageRoute 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::getFormModeListPageRoute()

Generate routes to use `add-list` entity operation per form modes.

Parameters

array $form_mode_infos: An associative array represent a DisplayForm entity.

Return value

\Symfony\Component\Routing\Route|null The generated route, if available.

1 call to FormModesSubscriber::getFormModeListPageRoute()
FormModesSubscriber::setAddPageCollection in src/Routing/EventSubscriber/FormModesSubscriber.php
Add one route for `add_page` entity operation per form_mode.

File

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

Class

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

Namespace

Drupal\form_mode_manager\Routing\EventSubscriber

Code

public function getFormModeListPageRoute(array $form_mode_infos) {
  $form_mode_machine_name = $this->formModeManager
    ->getFormModeMachineName($form_mode_infos['id']);
  $entity_type_id = $this->entityDefinition
    ->id();
  $route = NULL;
  if ($this->formModeManager
    ->hasActiveFormMode($entity_type_id, $form_mode_machine_name)) {
    $route_path = implode('/', [
      $entity_type_id,
      'add-list',
      $this->formModeManager
        ->getFormModeMachineName($form_mode_infos['id']),
    ]);
    $route_defaults = [
      '_controller' => static::FORM_MODE_DEFAULT_CONTROLLER . '::addPage',
      '_title' => $this
        ->getListRouteTitle($form_mode_infos['label']),
      'form_mode_name' => $this->formModeManager
        ->getFormModeMachineName($form_mode_infos['id']),
    ];
    $route_requirements = [
      '_permission' => "use {$form_mode_infos['id']} form mode",
    ];
    $route_options = [
      '_form_mode_manager_entity_type_id' => $entity_type_id,
      '_form_mode_manager_bundle_entity_type_id' => $this->entityDefinition
        ->getBundleEntityType(),
      '_admin_route' => TRUE,
    ];
    $route = new Route("/{$route_path}", $route_defaults, $route_requirements, $route_options);
  }
  return $route;
}