diff --git a/bundle/Core/Sitemap/QueryFactory.php b/bundle/Core/Sitemap/QueryFactory.php index c6c33c8..92d08b4 100644 --- a/bundle/Core/Sitemap/QueryFactory.php +++ b/bundle/Core/Sitemap/QueryFactory.php @@ -69,11 +69,10 @@ public function __invoke(): Query $config = $this->configResolver->getParameter('sitemap_includes', 'nova_ezseo'); $criterions = array_merge( $criterions, - $this->getCriterionsForConfig( + $this->getCriterionsForIncludeConfig( $config['contentTypeIdentifiers'], $config['locations'], $config['subtrees'], - false ) ); @@ -142,4 +141,55 @@ function ($criterion) { return $criterions; } + + private function getCriterionsForIncludeConfig( + array $contentTypeIdentifiers, + array $locationIds, + array $subtreeLocationsId, + ) + { + $contentTypeService = $this->repository->getContentTypeService(); + $criterions = []; + + $validContentTypeIdentifiers = []; + foreach ($contentTypeIdentifiers as $contentTypeIdentifier) { + try { + $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); + } catch (NotFoundException $exception) { + dd($contentTypeIdentifier); + continue; + } + $validContentTypeIdentifiers[] = $contentTypeIdentifier; + } + if (count($validContentTypeIdentifiers) > 0) { + $criterions[] = new Criterion\ContentTypeIdentifier($validContentTypeIdentifiers); + } + + $subtreePaths = []; + foreach ($subtreeLocationsId as $locationId) { + $includedLocation = $this->getLocation($locationId); + if (null === $includedLocation) { + continue; + } + $subtreePaths[] = $includedLocation->pathString; + } + if (count($subtreePaths) > 0) { + $criterions[] = new Criterion\Subtree($subtreePaths); + } + + $validLocationIds = []; + foreach ($locationIds as $locationId) { + $includedLocation = $this->getLocation($locationId); + if (null === $includedLocation) { + continue; + } + $validLocationIds[] = $locationId; + } + + if (count($validLocationIds) > 0) { + $criterions[] = new Criterion\LocationId($validLocationIds); + } + + return $criterions; + } }