/** * 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, array('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->structureManager->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; }
/** * It should get an extension. */ public function testGetExtension() { $this->extensionManager->getExtension('content', 'foo')->willReturn($this->extension->reveal()); $extension = $this->structureManager->getExtension('content', 'foo'); $this->assertSame($this->extension->reveal(), $extension); }