You are here

public function ServiceResourceBaseForm::getEntityFromRouteMatch in Services 9.0.x

Same name and namespace in other branches
  1. 8.4 src/Form/ServiceResourceBaseForm.php \Drupal\services\Form\ServiceResourceBaseForm::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/ServiceResourceBaseForm.php, line 35

Class

ServiceResourceBaseForm
Class \Drupal\services\Form\ServiceResourceBaseForm.

Namespace

Drupal\services\Form

Code

public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
  if ($route_match
    ->getRawParameter('service_endpoint') !== NULL && $route_match
    ->getRawParameter('plugin_id') !== NULL) {
    $service_endpoint = $route_match
      ->getParameter('service_endpoint');
    $entity = $service_endpoint
      ->loadResourceProvider($route_match
      ->getRawParameter('plugin_id'));
  }
  if (!isset($entity) || FALSE === $entity) {
    $entity = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->create([]);
  }
  return $entity;
}