public EntityForm::getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id)
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 EntityFormInterface::getEntityFromRouteMatch
File
- core/lib/Drupal/Core/Entity/EntityForm.php, line 351
Class
- EntityForm
- Base class for entity forms.
Namespace
Drupal\Core\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public function getEntityFromRouteMatch(RouteMatchInterface $route_match , $entity_type_id ) { if ( $route_match ->getRawParameter( $entity_type_id ) !== NULL) { $entity = $route_match ->getParameter( $entity_type_id ); } else { $values = []; // If the entity has bundles, fetch it from the route match. $entity_type = $this ->entityTypeManager->getDefinition( $entity_type_id ); if ( $bundle_key = $entity_type ->getKey( 'bundle' )) { if (( $bundle_entity_type_id = $entity_type ->getBundleEntityType()) && $route_match ->getRawParameter( $bundle_entity_type_id )) { $values [ $bundle_key ] = $route_match ->getParameter( $bundle_entity_type_id )->id(); } elseif ( $route_match ->getRawParameter( $bundle_key )) { $values [ $bundle_key ] = $route_match ->getParameter( $bundle_key ); } } $entity = $this ->entityTypeManager->getStorage( $entity_type_id )->create( $values ); } return $entity ; } |
Please login to continue.