You are here

public function SimpleEntityFormModes::getEntity in Form mode manager 8.2

Return value

\Drupal\Core\Entity\EntityInterface The entity loaded form route_match.

Throws

\Exception If an invalid entity is retrieving from the route object.

Overrides AbstractEntityFormModesFactory::getEntity

File

src/SimpleEntityFormModes.php, line 75

Class

SimpleEntityFormModes
Route controller factory specific for each entities not using bundles.

Namespace

Drupal\form_mode_manager

Code

public function getEntity(RouteMatchInterface $route_match) {

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this
    ->getEntityFromRouteMatch($route_match);
  if (empty($entity)) {
    $route_entity_type_info = $this
      ->getEntityTypeFromRouteMatch($route_match);

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this->entityTypeManager
      ->getStorage($route_entity_type_info['entity_type_id'])
      ->create();
  }
  return $entity;
}