5

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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