public function WishlistItemForm::getEntityFromRouteMatch in Commerce Wishlist 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/ WishlistItemForm.php, line 74
Class
- WishlistItemForm
- Defines the wishlist item add/edit form.
Namespace
Drupal\commerce_wishlist\FormCode
public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) {
if ($route_match
->getRawParameter('commerce_wishlist_item') !== NULL) {
$entity = $route_match
->getParameter('commerce_wishlist_item');
}
else {
/** @var \Drupal\commerce_wishlist\Entity\WishlistInterface $wishlist */
$wishlist = $route_match
->getParameter('commerce_wishlist');
// Set parent wishlist id.
$values = [
'wishlist_id' => $wishlist
->id(),
'type' => 'commerce_product_variation',
];
$entity = $this->entityTypeManager
->getStorage('commerce_wishlist_item')
->create($values);
}
return $entity;
}