public function ProductVariationForm::getEntityFromRouteMatch in Commerce Core 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
- modules/
product/ src/ Form/ ProductVariationForm.php, line 20
Class
- ProductVariationForm
- Defines the add/edit/duplicate form for product variations.
Namespace
Drupal\commerce_product\FormCode
public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
if ($route_match
->getRawParameter('commerce_product_variation') !== NULL) {
$entity = $route_match
->getParameter('commerce_product_variation');
}
else {
/** @var \Drupal\commerce_product\Entity\ProductInterface $product */
$product = $route_match
->getParameter('commerce_product');
/** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */
$product_type = $this->entityTypeManager
->getStorage('commerce_product_type')
->load($product
->bundle());
$values = [
'type' => $product_type
->getVariationTypeId(),
'product_id' => $product
->id(),
];
$entity = $this->entityTypeManager
->getStorage('commerce_product_variation')
->create($values);
}
return $entity;
}