You are here

public function EntityExtraFieldForm::getEntityFromRouteMatch in Entity Extra Field 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EntityExtraFieldForm.php \Drupal\entity_extra_field\Form\EntityExtraFieldForm::getEntityFromRouteMatch()

Determines which entity will be used by this form from a RouteMatch object.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

string $entity_type_id: The entity type identifier.

Return value

\Drupal\Core\Entity\EntityInterface The entity object as determined from the passed-in route match.

Overrides EntityForm::getEntityFromRouteMatch

File

src/Form/EntityExtraFieldForm.php, line 279

Class

EntityExtraFieldForm
Define entity extra field form.

Namespace

Drupal\entity_extra_field\Form

Code

public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
  if ($route_match
    ->getRawParameter($entity_type_id) !== NULL) {
    $entity = $route_match
      ->getParameter($entity_type_id);
  }
  else {
    $values = [];
    $type_manager = $this->entityTypeManager;
    if ($base_entity_type_id = $route_match
      ->getParameter('entity_type_id')) {
      $definition = $type_manager
        ->getDefinition($base_entity_type_id);
      $values['base_entity_type_id'] = $base_entity_type_id;
      $bundle_type = $definition
        ->getBundleEntityType();
      if ($base_bundle_type = $route_match
        ->getParameter($bundle_type)) {
        $values['base_bundle_type_id'] = $base_bundle_type
          ->id();
      }
    }
    $entity = $type_manager
      ->getStorage($entity_type_id)
      ->create($values);
  }
  return $entity;
}