getExtension() 공개 메소드

Returns a extension.
public getExtension ( string $key, string $name ) : Sulu\Component\Content\Extension\ExtensionInterface
$key string
$name string
리턴 Sulu\Component\Content\Extension\ExtensionInterface
예제 #1
0
 /**
  * It should hydrate data from extensions.
  */
 public function testHydrateExtensionsData()
 {
     $expectedData = ['foo' => 'bar'];
     $document = new TestExtensionDocument();
     $this->hydrateEvent->getLocale()->shouldNotBeCalled();
     $this->hydrateEvent->getDocument()->willReturn($document);
     $this->inspector->getWebspace($document)->willReturn('sulu_io');
     $this->inspector->getLocale($document)->shouldBeCalled()->willReturn('de');
     $this->namespaceRegistry->getPrefix('extension_localized')->willReturn('ext_prefix');
     $this->extensionManager->getExtension('foobar', 'ext_1')->willReturn($this->extension->reveal());
     $this->extension->getName()->willReturn('ext_1');
     $this->extension->setLanguageCode('de', 'ext_prefix', '')->shouldBeCalled();
     $this->extension->load($this->node->reveal(), 'sulu_io', 'de')->willReturn($expectedData);
     $this->subscriber->handleHydrate($this->hydrateEvent->reveal());
     $this->assertEquals($document->getExtensionsData()->offsetGet('ext_1'), $expectedData);
 }
예제 #2
0
 /**
  * Returns a select statement for excerpt data.
  */
 private function buildSelectorForExcerpt($locale, &$additionalFields)
 {
     $excerptStructure = $this->structureManager->getStructure('excerpt');
     $extension = $this->extensionManager->getExtension('', 'excerpt');
     foreach ($excerptStructure->getProperties(true) as $property) {
         $additionalFields[$locale][] = ['extension' => $extension, 'target' => 'excerpt', 'property' => $property->getName(), 'name' => $property->getName()];
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function resolve(StructureInterface $structure)
 {
     $data = ['view' => [], 'content' => [], 'uuid' => $structure->getUuid(), 'creator' => $structure->getCreator(), 'changer' => $structure->getChanger(), 'created' => $structure->getCreated(), 'changed' => $structure->getChanged(), 'template' => $structure->getKey(), 'path' => $structure->getPath()];
     if ($structure instanceof PageBridge) {
         $data['extension'] = $structure->getExt()->toArray();
         $data['urls'] = $structure->getUrls();
         $data['published'] = $structure->getPublished();
         $data['shadowBaseLocale'] = $structure->getShadowBaseLanguage();
         foreach ($data['extension'] as $name => $value) {
             $extension = $this->extensionManager->getExtension($structure->getKey(), $name);
             $data['extension'][$name] = $extension->getContentData($value);
         }
     }
     foreach ($structure->getProperties(true) as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $data['view'][$property->getName()] = $contentType->getViewData($property);
         $data['content'][$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
예제 #4
0
파일: Webspace.php 프로젝트: sulu/sulu
 /**
  * Returns a flat array with the extensions of the given document.
  *
  * @param BasePageDocument $document
  * @param string $format
  *
  * @return array
  */
 protected function getExtensionData(BasePageDocument $document, $format)
 {
     $extensionData = [];
     foreach ($document->getExtensionsData()->toArray() as $extensionName => $extensionProperties) {
         /** @var \Sulu\Bundle\ContentBundle\Content\Structure\ExcerptStructureExtension $extension */
         $extension = $this->extensionManager->getExtension($document->getStructureType(), $extensionName);
         if ($extension instanceof ExportExtensionInterface) {
             $extensionData[$extensionName] = $extension->export($extensionProperties, $format);
         }
     }
     return $extensionData;
 }
예제 #5
0
 /**
  * Lazily evaluate the value for the given extension.
  *
  * @param string $extensionName
  *
  * @return mixed
  */
 public function offsetGet($extensionName)
 {
     if (isset($this->data[$extensionName])) {
         return $this->data[$extensionName];
     }
     $extension = $this->extensionManager->getExtension($this->structureType, $extensionName);
     // TODO: should not pass namespace here.
     //       and indeed this call should be removed and the extension should be
     //       passed the document.
     $extension->setLanguageCode($this->locale, $this->prefix, $this->internalPrefix);
     // passing the webspace and locale would also be unnecessary if we passed the
     // document
     $data = $extension->load($this->node, $this->webspaceName, $this->locale);
     $this->data[$extensionName] = $data;
     return $data;
 }
예제 #6
0
파일: ContentMapper.php 프로젝트: sulu/sulu
 /**
  * TODO: Refactor this .. this should be handled in a listener or in the form, or something
  * {@inheritdoc}
  */
 public function saveExtension($uuid, $data, $extensionName, $webspaceKey, $locale, $userId)
 {
     $document = $this->loadDocument($uuid, $locale, ['exclude_ghost' => true]);
     if ($document === null) {
         throw new TranslatedNodeNotFoundException($uuid, $locale);
     }
     if (!$document instanceof ExtensionBehavior) {
         throw new \RuntimeException(sprintf('Document of class "%s" must implement the ExtensionableBehavior if it is to be extended', get_class($document)));
     }
     // save data of extensions
     $extension = $this->extensionManager->getExtension($document->getStructureType(), $extensionName);
     $node = $this->inspector->getNode($document);
     $extension->save($node, $data, $webspaceKey, $locale);
     $extensionData = $extension->load($node, $webspaceKey, $locale);
     $document->setExtension($extension->getName(), $extensionData);
     $this->documentManager->flush();
     $structure = $this->documentToStructure($document);
     $event = new ContentNodeEvent($node, $structure);
     $this->eventDispatcher->dispatch(ContentEvents::NODE_POST_SAVE, $event);
     return $structure;
 }