Skip to content
Snippets Groups Projects
Commit 759a6180 authored by Matthieu Scarset's avatar Matthieu Scarset
Browse files

Try/catch to avoid potential exceptions #3251675

parent 42c3dd11
Branches
Tags
No related merge requests found
......@@ -224,19 +224,23 @@ class MenuLinkTreeManipulators {
return FALSE;
}
// Get entity info from route.
// @see https://www.drupal.org/project/menu_manipulator/issues/3251675
// @see https://www.computerminds.co.uk/drupal-code/get-entity-route
$route_match = $this->router->match($uri);
if ($route = $route_match['_route_object'] ?? NULL) {
foreach ($route->getOption('parameters') as $name => $options) {
if (isset($options['type']) && strpos($options['type'], 'entity:') === 0) {
$entity = $route_match[$name] ?? NULL;
if ($entity instanceof EntityInterface) {
return $this->entityRepository->getActive($entity->getEntityTypeId(), $entity->id());
try {
// Get entity info from route.
// @see https://www.drupal.org/project/menu_manipulator/issues/3251675
// @see https://www.computerminds.co.uk/drupal-code/get-entity-route
$route_match = $this->router->match($uri);
if ($route = $route_match['_route_object'] ?? NULL) {
foreach ($route->getOption('parameters') as $name => $options) {
if (isset($options['type']) && strpos($options['type'], 'entity:') === 0) {
$entity = $route_match[$name] ?? NULL;
if ($entity instanceof EntityInterface) {
return $this->entityRepository->getActive($entity->getEntityTypeId(), $entity->id());
}
}
}
}
} catch (\Exception $e) {
/* Fail silently */
}
return FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment