You are here

public function FormModesSubscriber::getFormModeListPageRoute in Form mode manager 8

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

Generate route to Form Mode Manager `add-list` route.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is, used for multiple, possibly dynamic entity types.

array $form_mode: 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
Set one add_page route per form_mode for compatible entities.

File

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

Class

FormModesSubscriber
Subscriber for form_mode_manager routes.

Namespace

Drupal\form_mode_manager\Routing\EventSubscriber

Code

public function getFormModeListPageRoute(EntityTypeInterface $entity_type, array $form_mode) {
  $route = NULL;
  $entity_type_id = $entity_type
    ->id();
  $entity_type_bundle_id = $entity_type
    ->getBundleEntityType();
  $bundle_entity_type_id = !empty($entity_type_bundle_id) ? $entity_type_bundle_id : $entity_type_id;
  $has_active_mode = $this->formModeManager
    ->hasActiveFormMode($entity_type_id, $this->formModeManager
    ->getFormModeMachineName($form_mode['id']));
  if ($has_active_mode) {
    $route = new Route("/{$entity_type_id}/add-list/{$this->formModeManager->getFormModeMachineName($form_mode['id'])}");
    $route
      ->addDefaults([
      '_controller' => static::FORM_MODE_DEFAULT_CONTROLLER . '::addPage',
      '_title' => $this
        ->t('Add @entity_type', [
        '@entity_type' => $entity_type
          ->getLabel(),
      ])
        ->render(),
      'form_mode_name' => $this->formModeManager
        ->getFormModeMachineName($form_mode['id']),
    ])
      ->addRequirements([
      '_permission' => "use {$form_mode['id']} form mode",
    ])
      ->setOptions([
      '_form_mode_manager_entity_type_id' => $entity_type_id,
      '_form_mode_manager_bundle_entity_type_id' => $bundle_entity_type_id,
      '_admin_route' => TRUE,
    ]);
    $this
      ->userListEnhancements($route, $entity_type
      ->id());
  }
  return $route;
}