diff --git a/bundle/Twig/NovaeZSEOExtension.php b/bundle/Twig/NovaeZSEOExtension.php index dd10721..c24e895 100644 --- a/bundle/Twig/NovaeZSEOExtension.php +++ b/bundle/Twig/NovaeZSEOExtension.php @@ -16,6 +16,8 @@ use eZ\Publish\API\Repository\Values\Content\ContentInfo; use eZ\Publish\API\Repository\Values\Content\Field; use eZ\Publish\API\Repository\Values\ContentType\ContentType; +use eZ\Publish\Core\Base\Exceptions\NotFoundException; +use eZ\Publish\Core\Base\Exceptions\UnauthorizedException; use eZ\Publish\Core\MVC\ConfigResolverInterface; use eZ\Publish\Core\MVC\Symfony\Locale\LocaleConverter; use Novactive\Bundle\eZSEOBundle\Core\CustomFallbackInterface; @@ -63,6 +65,11 @@ class NovaeZSEOExtension extends AbstractExtension implements GlobalsInterface */ protected $customFallBackService; + /** + * @var LoggerInterface|null + */ + protected $logger; + public function __construct( Repository $repository, MetaNameSchema $nameSchema, @@ -75,6 +82,14 @@ public function __construct( $this->localeConverter = $localeConverter; } + /** + * @required + */ + public function setLogger(LoggerInterface $logger): void + { + $this->logger = $logger; + } + public function setCustomFallbackService(CustomFallbackInterface $service) { $this->customFallBackService = $service; @@ -178,8 +193,17 @@ protected function innerComputeMetas( $meta->setContent($configuration[$meta->getName()]); } } - if (!$this->metaNameSchema->resolveMeta($meta, $content, $contentType)) { - $needFallback = true; + try { + if (!$this->metaNameSchema->resolveMeta($meta, $content, $contentType)) { + $needFallback = true; + } + } catch (NotFoundException|UnauthorizedException $exception) { + if ($this->logger) { + $this->logger->error('[Nova eZ SEO] Error when resolving meta', [ + 'message' => $exception->getMessage(), + 'contentId' => $content->id, + ]); + } } }