From 0467aae68d25477c6fdddfb27e1442bb8e2ca9ff Mon Sep 17 00:00:00 2001 From: jmahlke Date: Thu, 11 Nov 2021 15:38:59 +0100 Subject: [PATCH] add Extension System for StructureResolver --- Content/StructureResolver.php | 14 +++++++++++++- .../StructureResolverExtensionInterface.php | 19 +++++++++++++++++++ Resources/config/services.xml | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Content/StructureResolver/StructureResolverExtensionInterface.php diff --git a/Content/StructureResolver.php b/Content/StructureResolver.php index fd15f0d..19354a7 100644 --- a/Content/StructureResolver.php +++ b/Content/StructureResolver.php @@ -13,6 +13,7 @@ namespace Sulu\Bundle\HeadlessBundle\Content; +use Sulu\Bundle\HeadlessBundle\Content\StructureResolver\StructureResolverExtensionInterface; use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector; use Sulu\Bundle\PageBundle\Document\BasePageDocument; use Sulu\Bundle\PageBundle\Preview\PageRouteDefaultsProvider; @@ -50,16 +51,23 @@ class StructureResolver implements StructureResolverInterface */ private $referenceStorePool; + /** + * @var StructureResolverExtensionInterface[] + */ + private iterable $structureResolverExtensions; + public function __construct( ContentResolverInterface $contentResolver, StructureManagerInterface $structureManager, DocumentInspector $documentInspector, - ReferenceStorePoolInterface $referenceStorePool + ReferenceStorePoolInterface $referenceStorePool, + iterable $structureResolverExtensions ) { $this->contentResolver = $contentResolver; $this->structureManager = $structureManager; $this->documentInspector = $documentInspector; $this->referenceStorePool = $referenceStorePool; + $this->structureResolverExtensions = $structureResolverExtensions; } /** @@ -95,6 +103,10 @@ public function resolve( $data['view'][$property->getName()] = $contentView->getView(); } + foreach ($this->structureResolverExtensions as $structureResolverExtension) { + $data[$structureResolverExtension->getKey()] = $structureResolverExtension->resolve($requestedStructure, $locale); + } + return $data; } diff --git a/Content/StructureResolver/StructureResolverExtensionInterface.php b/Content/StructureResolver/StructureResolverExtensionInterface.php new file mode 100644 index 0000000..520852c --- /dev/null +++ b/Content/StructureResolver/StructureResolverExtensionInterface.php @@ -0,0 +1,19 @@ + + +