You are here

public function RulesComponentAddForm::getEntityFromRouteMatch in Rules 8.3

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/RulesComponentAddForm.php, line 16

Class

RulesComponentAddForm
Provides a form to add a component.

Namespace

Drupal\rules\Form

Code

public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {

  // Overridden to customize creation of new entities.
  if ($route_match
    ->getRawParameter($entity_type_id) !== NULL) {
    $entity = $route_match
      ->getParameter($entity_type_id);
  }
  else {
    $values = [];

    // @todo Create the right expression depending on the route.
    $entity = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->create($values);
    $entity
      ->setExpression($this->expressionManager
      ->createRule());
  }
  return $entity;
}