You are here

public function GroupRoleForm::getEntityFromRouteMatch in Group 2.0.x

Same name and namespace in other branches
  1. 8 src/Entity/Form/GroupRoleForm.php \Drupal\group\Entity\Form\GroupRoleForm::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/Entity/Form/GroupRoleForm.php, line 151

Class

GroupRoleForm
Form controller for group role forms.

Namespace

Drupal\group\Entity\Form

Code

public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
  if ($route_match
    ->getRawParameter($entity_type_id) !== NULL) {
    return $route_match
      ->getParameter($entity_type_id);
  }

  // If we are on the create form, we can't extract an entity from the route,
  // so we need to create one based on the route parameters.
  $values = [];
  if ($route_match
    ->getRawParameter('group_type') !== NULL) {
    $values['group_type'] = $route_match
      ->getRawParameter('group_type');
  }
  return $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->create($values);
}