vendor/sulu/sulu/src/Sulu/Bundle/SnippetBundle/Snippet/SnippetResolver.php line 59

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\SnippetBundle\Snippet;
  11. use Sulu\Bundle\WebsiteBundle\Resolver\StructureResolverInterface;
  12. use Sulu\Component\Content\Mapper\ContentMapperInterface;
  13. /**
  14.  * Resolves snippets by UUIDs.
  15.  */
  16. class SnippetResolver implements SnippetResolverInterface
  17. {
  18.     /**
  19.      * @var array
  20.      */
  21.     private $snippetCache = [];
  22.     /**
  23.      * @var ContentMapperInterface
  24.      */
  25.     private $contentMapper;
  26.     /**
  27.      * @var StructureResolverInterface
  28.      */
  29.     private $structureResolver;
  30.     public function __construct(
  31.         ContentMapperInterface $contentMapper,
  32.         StructureResolverInterface $structureResolver
  33.     ) {
  34.         $this->contentMapper $contentMapper;
  35.         $this->structureResolver $structureResolver;
  36.     }
  37.     public function resolve($uuids$webspaceKey$locale$shadowLocale null$loadExcerpt false)
  38.     {
  39.         $snippets = [];
  40.         foreach ($uuids as $uuid) {
  41.             if (!\array_key_exists($uuid$this->snippetCache)) {
  42.                 $snippet $this->contentMapper->load($uuid$webspaceKey$locale);
  43.                 if (!$snippet->getHasTranslation() && null !== $shadowLocale) {
  44.                     $snippet $this->contentMapper->load($uuid$webspaceKey$shadowLocale);
  45.                 }
  46.                 $snippet->setIsShadow(null !== $shadowLocale);
  47.                 $snippet->setShadowBaseLanguage($shadowLocale);
  48.                 $resolved $this->structureResolver->resolve($snippet$loadExcerpt);
  49.                 if ($loadExcerpt) {
  50.                     $resolved['content']['taxonomies'] = [
  51.                         'categories' => $resolved['extension']['excerpt']['categories'],
  52.                         'tags' => $resolved['extension']['excerpt']['tags'],
  53.                     ];
  54.                 }
  55.                 $resolved['view']['template'] = $snippet->getKey();
  56.                 $resolved['view']['uuid'] = $snippet->getUuid();
  57.                 $this->snippetCache[$uuid] = $resolved;
  58.             }
  59.             $snippets[] = $this->snippetCache[$uuid];
  60.         }
  61.         return $snippets;
  62.     }
  63. }