From db0db7e36ea972d1957718d87f9283bcf9aebda7 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Mon, 14 Aug 2023 15:10:28 +0200 Subject: [PATCH] IBX-6312: View matcher ParentContentType should not throw execption if parent is not available --- .../ContentBased/Id/ParentContentType.php | 10 +++++++--- .../Identifier/ParentContentType.php | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Id/ParentContentType.php b/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Id/ParentContentType.php index baf3bbe15e..fec16046f9 100644 --- a/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Id/ParentContentType.php +++ b/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Id/ParentContentType.php @@ -56,9 +56,13 @@ public function match(View $view) if (!$view instanceof LocationValueView) { return false; } - $parent = $this->loadParentLocation( - $view->getLocation()->parentLocationId - ); + try { + $parent = $this->loadParentLocation( + $view->getLocation()->parentLocationId + ); + } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) { + return false; + } return isset($this->values[$parent->getContentInfo()->contentTypeId]); } diff --git a/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Identifier/ParentContentType.php b/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Identifier/ParentContentType.php index 612f2e6616..d7a95862e7 100644 --- a/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Identifier/ParentContentType.php +++ b/eZ/Publish/Core/MVC/Symfony/Matcher/ContentBased/Identifier/ParentContentType.php @@ -25,15 +25,19 @@ class ParentContentType extends MultipleValued */ public function matchLocation(APILocation $location) { - $parentContentType = $this->repository->sudo( - static function (Repository $repository) use ($location) { - $parent = $repository->getLocationService()->loadLocation($location->parentLocationId); + try { + $parentContentType = $this->repository->sudo( + static function (Repository $repository) use ($location) { + $parent = $repository->getLocationService()->loadLocation($location->parentLocationId); - return $repository - ->getContentTypeService() - ->loadContentType($parent->getContentInfo()->contentTypeId); - } - ); + return $repository + ->getContentTypeService() + ->loadContentType($parent->getContentInfo()->contentTypeId); + } + ); + } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) { + return false; + } return isset($this->values[$parentContentType->identifier]); }