I have a URI 'entity:node/27' and I want to load this entity, but I cannot find the correct helper function or class to use.

I do not want to explode the string or regex the string, I am fairly sure there is a function for this.


1 Answer 1

$params = Url::fromUri("internal:" . $source_uri)->getRouteParameters();
$entity_type = key($params);
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($params[$entity_type]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.