You are here

public function ComplexEntityFormModes::getEntityTypeFromRouteMatch in Form mode manager 8.2

Return value

array The entity object as determined from the passed-in route match.

Overrides AbstractEntityFormModesFactory::getEntityTypeFromRouteMatch

1 call to ComplexEntityFormModes::getEntityTypeFromRouteMatch()
ComplexEntityFormModes::getEntity in src/ComplexEntityFormModes.php

File

src/ComplexEntityFormModes.php, line 158

Class

ComplexEntityFormModes
Route controller factory specific for each entities using bundles.

Namespace

Drupal\form_mode_manager

Code

public function getEntityTypeFromRouteMatch(RouteMatchInterface $route_match) {
  $route = $route_match
    ->getRouteObject();
  $entity_type_id = $route
    ->getOption('_form_mode_manager_entity_type_id');
  $bundle_entity_type_id = $route
    ->getOption('_form_mode_manager_bundle_entity_type_id');
  $form_mode = $this->formModeManager
    ->getFormModeMachineName($route
    ->getDefault('_entity_form'));
  $bundle = $route_match
    ->getRawParameter($bundle_entity_type_id);
  $form_mode_definition = $this->formModeManager
    ->getActiveDisplaysByBundle($entity_type_id, $bundle);
  $entity_type_key = $this->entityTypeManager
    ->getDefinition($entity_type_id)
    ->getKey('bundle');
  return [
    'bundle' => $bundle,
    'bundle_entity_type' => $bundle_entity_type_id,
    'entity_key' => $entity_type_key,
    'entity_type_id' => $entity_type_id,
    'form_mode' => isset($form_mode_definition[$entity_type_id][$form_mode]) ? $form_mode_definition[$entity_type_id][$form_mode] : NULL,
  ];
}