Last active
October 20, 2017 10:05
-
-
Save wachterjohannes/2bdef03d009d695144858417d3032095 to your computer and use it in GitHub Desktop.
Document to twig structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultController extends WebsiteController | |
{ | |
public function indexAction(StructureInterface $structure, $preview = false, $partial = false) | |
{ | |
$document = $this->loadDocument('/test', $structure->getLanguageCode(), $structure->getWebspaceKey()); | |
return $this->renderStructure( | |
$structure, | |
[ | |
'page' => $this->resolve($this->documentToStructure($document)), | |
], | |
$preview, | |
$partial | |
); | |
} | |
protected function loadDocument($url, $locale, $webspaceKey) | |
{ | |
$resourceLocatorStrategyPool = $this->get('sulu.content.resource_locator.strategy_pool'); | |
$resourceLocatorStrategy = $resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey); | |
$document = $this->get('sulu_document_manager.document_manager')->find( | |
$resourceLocatorStrategy->loadByResourceLocator( | |
rtrim($resourceLocator, '/'), | |
$webspaceKey, | |
$locale | |
), | |
$locale, | |
[ | |
'load_ghost_content' => false, | |
] | |
); | |
} | |
protected function documentToStructure(BasePageDocument $document) | |
{ | |
$inspector = $this->get('sulu_document_manager.document_inspector'); | |
$structure = $inspector->getStructureMetadata($document); | |
$documentAlias = $inspector->getMetadata($document)->getAlias(); | |
$structureManager = $this->get('sulu.content.structure_manager'); | |
$structureBridge = $structureManager->wrapStructure($documentAlias, $structure); | |
$structureBridge->setDocument($document); | |
return $structureBridge; | |
} | |
protected function resolve(StructureInterface $structure) | |
{ | |
return $this->get('sulu_website.resolver.structure')->resolve($structure); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks… I hope that last question… How I can pass StructureInterface $structure to API node?