Sulu\Component\Content\Mapper\ContentMapper::saveExtension PHP Method

saveExtension() public method

. this should be handled in a listener or in the form, or something {@inheritdoc}
public saveExtension ( $uuid, $data, $extensionName, $webspaceKey, $locale, $userId )
    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;
    }

Usage Example

Exemplo n.º 1
0
 public function testTranslatedNodeNotFound()
 {
     $data = ['title' => 'Test', 'url' => '/test/test', 'blog' => 'Thats a good test'];
     $structure = $this->mapper->save($data, 'default', 'sulu_io', 'en', 1);
     $dataTest2DE = ['a' => 'de test2 a', 'b' => 'de test2 b'];
     $this->setExpectedException('Sulu\\Component\\Content\\Exception\\TranslatedNodeNotFoundException', 'Node "' . $structure->getUuid() . '" not found in localization "de"');
     $this->mapper->saveExtension($structure->getUuid(), $dataTest2DE, 'test2', 'sulu_io', 'de', 1);
 }