示例#1
0
 public function testResolve()
 {
     $this->contentTypeManager->get('content_type')->willReturn($this->contentType);
     $this->contentType->getViewData(Argument::any())->willReturn('view');
     $this->contentType->getContentData(Argument::any())->willReturn('content');
     $excerptExtension = $this->prophesize('Sulu\\Component\\Content\\Extension\\ExtensionInterface');
     $excerptExtension->getContentData(['test1' => 'test1'])->willReturn(['test1' => 'test1']);
     $this->structureManager->getExtension('test', 'excerpt')->willReturn($excerptExtension);
     $property = $this->prophesize('Sulu\\Component\\Content\\Compat\\PropertyInterface');
     $property->getName()->willReturn('property');
     $property->getContentTypeName()->willReturn('content_type');
     $structure = $this->prophesize('Sulu\\Component\\Content\\Compat\\Structure\\PageBridge');
     $structure->getKey()->willReturn('test');
     $structure->getExt()->willReturn(new ExtensionContainer(['excerpt' => ['test1' => 'test1']]));
     $structure->getUuid()->willReturn('some-uuid');
     $structure->getProperties(true)->willReturn([$property->reveal()]);
     $structure->getCreator()->willReturn(1);
     $structure->getChanger()->willReturn(1);
     $structure->getCreated()->willReturn('date');
     $structure->getChanged()->willReturn('date');
     $structure->getPublished()->willReturn('date');
     $structure->getPath()->willReturn('test-path');
     $structure->getUrls()->willReturn(['en' => '/description', 'de' => '/beschreibung', 'es' => null]);
     $structure->getShadowBaseLanguage()->willReturn('en');
     $expected = ['extension' => ['excerpt' => ['test1' => 'test1']], 'uuid' => 'some-uuid', 'view' => ['property' => 'view'], 'content' => ['property' => 'content'], 'creator' => 1, 'changer' => 1, 'created' => 'date', 'changed' => 'date', 'published' => 'date', 'template' => 'test', 'urls' => ['en' => '/description', 'de' => '/beschreibung', 'es' => null], 'path' => 'test-path', 'shadowBaseLocale' => 'en'];
     $this->assertEquals($expected, $this->structureResolver->resolve($structure->reveal()));
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function resolve(array $parameter, RequestAnalyzerInterface $requestAnalyzer = null, StructureInterface $structure = null, $preview = false)
 {
     if ($structure !== null) {
         $structureData = $this->structureResolver->resolve($structure);
     } else {
         $structureData = [];
     }
     if (!$preview) {
         $requestAnalyzerData = $this->requestAnalyzerResolver->resolve($requestAnalyzer);
     } else {
         $requestAnalyzerData = $this->requestAnalyzerResolver->resolveForPreview($structure->getWebspaceKey(), $structure->getLanguageCode());
     }
     if (null !== ($portal = $requestAnalyzer->getPortal())) {
         $allLocalizations = $portal->getLocalizations();
     } else {
         $allLocalizations = $requestAnalyzer->getWebspace()->getLocalizations();
     }
     $pageUrls = array_key_exists('urls', $structureData) ? $structureData['urls'] : [];
     $urls = [];
     foreach ($allLocalizations as $localization) {
         /* @var Localization $localization */
         $locale = $localization->getLocalization();
         if (array_key_exists($locale, $pageUrls)) {
             $urls[$locale] = $pageUrls[$locale];
         } else {
             $urls[$locale] = '/';
         }
     }
     $structureData['urls'] = $urls;
     return array_merge($parameter, $structureData, $requestAnalyzerData);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function loadSnippet($uuid, $locale = null)
 {
     if ($locale === null) {
         $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
     }
     try {
         $snippet = $this->contentMapper->load($uuid, $this->requestAnalyzer->getWebspace()->getKey(), $locale);
         return $this->structureResolver->resolve($snippet);
     } catch (DocumentNotFoundException $ex) {
         return;
     }
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function resolve($uuids, $webspaceKey, $locale, $shadowLocale = null)
 {
     $snippets = [];
     foreach ($uuids as $uuid) {
         if (!array_key_exists($uuid, $this->snippetCache)) {
             $snippet = $this->contentMapper->load($uuid, $webspaceKey, $locale);
             if (!$snippet->getHasTranslation() && $shadowLocale !== null) {
                 $snippet = $this->contentMapper->load($uuid, $webspaceKey, $shadowLocale);
             }
             $snippet->setIsShadow($shadowLocale !== null);
             $snippet->setShadowBaseLanguage($shadowLocale);
             $resolved = $this->structureResolver->resolve($snippet);
             $resolved['view']['template'] = $snippet->getKey();
             $resolved['view']['uuid'] = $snippet->getUuid();
             $this->snippetCache[$uuid] = $resolved;
         }
         $snippets[] = $this->snippetCache[$uuid];
     }
     return $snippets;
 }
示例#5
0
 /**
  * load snippet and serialize them.
  *
  * additionally cache it by id in this class
  */
 private function loadSnippets($ids, $webspaceKey, $locale, $shadowLocale = null)
 {
     $snippets = [];
     foreach ($ids as $i => $ref) {
         if (!array_key_exists($ref, $this->snippetCache)) {
             $snippet = $this->contentMapper->load($ref, $webspaceKey, $locale);
             if (!$snippet->getHasTranslation() && $shadowLocale !== null) {
                 $snippet = $this->contentMapper->load($ref, $webspaceKey, $shadowLocale);
             }
             $resolved = $this->structureResolver->resolve($snippet);
             $resolved['view']['template'] = $snippet->getKey();
             $this->snippetCache[$ref] = $resolved;
         }
         $snippets[] = $this->snippetCache[$ref];
     }
     return $snippets;
 }
 /**
  * @param string $uuid
  * @return array
  */
 public function load($uuid)
 {
     $contentStructure = $this->contentMapper->load($uuid, $this->requestAnalyzer->getWebspace()->getKey(), $this->requestAnalyzer->getCurrentLocalization()->getLocalization());
     return $this->structureResolver->resolve($contentStructure);
 }