You are here

public function ComplexEntityFormModes::getEntityFromRouteMatch in Form mode manager 8.2

Return value

\Drupal\Core\Entity\EntityInterface A new entity object build with given route_match.

Overrides AbstractEntityFormModesFactory::getEntityFromRouteMatch

1 call to ComplexEntityFormModes::getEntityFromRouteMatch()
ComplexEntityFormModes::getEntity in src/ComplexEntityFormModes.php
2 methods override ComplexEntityFormModes::getEntityFromRouteMatch()
MediaEntityFormModes::getEntityFromRouteMatch in src/MediaEntityFormModes.php
Retrieves entity from route match.
TaxonomyEntityFormModes::getEntityFromRouteMatch in src/TaxonomyEntityFormModes.php
Retrieves entity from route match.

File

src/ComplexEntityFormModes.php, line 136

Class

ComplexEntityFormModes
Route controller factory specific for each entities using bundles.

Namespace

Drupal\form_mode_manager

Code

public function getEntityFromRouteMatch(RouteMatchInterface $route_match) {
  $entity_type_id = $route_match
    ->getRouteObject()
    ->getOption('_form_mode_manager_entity_type_id');
  $bundle_entity_type_id = $route_match
    ->getRouteObject()
    ->getOption('_form_mode_manager_bundle_entity_type_id');
  $entity = $route_match
    ->getParameter($entity_type_id);
  if (empty($entity)) {
    $entity = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->create([
      'type' => $route_match
        ->getRawParameter($bundle_entity_type_id),
    ]);
  }
  return $entity;
}