You are here

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

Get the Form Mode Manager route for given operation.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection to retrieve parent entity routes.

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

array $form_mode: The form mode info.

string $operation: The entity operation name.

Return value

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

1 call to FormModesSubscriber::getFormModeRoute()
FormModesSubscriber::setFormModeCollection in src/Routing/EventSubscriber/FormModesSubscriber.php
Create a route per form_mode for given operation form.

File

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

Class

FormModesSubscriber
Subscriber for form_mode_manager routes.

Namespace

Drupal\form_mode_manager\Routing\EventSubscriber

Code

public function getFormModeRoute(RouteCollection $collection, EntityTypeInterface $entity_type, array $form_mode, $operation) {
  $entity_type_id = $entity_type
    ->id();
  $has_active_mode = $this->formModeManager
    ->hasActiveFormMode($entity_type_id, $this->formModeManager
    ->getFormModeMachineName($form_mode['id']));

  /** @var \Drupal\form_mode_manager\EntityRoutingMapBase $entity_operation_mapping */
  $entity_operation_mapping = $this->entityRoutingMap
    ->createInstance($entity_type_id, [
    'entityTypeId' => $entity_type_id,
  ]);
  if ($has_active_mode && ($entity_edit_route = $collection
    ->get($entity_operation_mapping
    ->getOperation($operation)))) {
    return $this
      ->setRoutes($entity_edit_route, $entity_type, $form_mode);
  }
  return NULL;
}