public function PriceListItemForm::getEntityFromRouteMatch in Commerce Pricelist 8.2
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/ PriceListItemForm.php, line 32
Class
Namespace
Drupal\commerce_pricelist\FormCode
public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
if ($route_match
->getRawParameter($entity_type_id) !== NULL) {
$entity = $route_match
->getParameter($entity_type_id);
}
elseif ($product_variation = $route_match
->getParameter('commerce_product_variation')) {
$values = [
'type' => 'commerce_product_variation',
'purchasable_entity' => $product_variation
->id(),
];
$entity = $this->entityTypeManager
->getStorage($entity_type_id)
->create($values);
}
else {
// Price lists and price list items share the same bundle.
$price_list = $route_match
->getParameter('commerce_pricelist');
$values = [
'type' => $price_list
->bundle(),
'price_list_id' => $price_list
->id(),
];
$entity = $this->entityTypeManager
->getStorage($entity_type_id)
->create($values);
}
return $entity;
}