diff --git a/Classes/Controller/ApiController.php b/Classes/Controller/ApiController.php index 750aa9a..1cc9d5c 100644 --- a/Classes/Controller/ApiController.php +++ b/Classes/Controller/ApiController.php @@ -157,8 +157,20 @@ protected function getStyleguideObjects($sitePackageKey): array $styleguideObjects = $this->fusionService->getStyleguideObjectsFromFusionAst($fusionAst); $prototypeStructures = $this->configurationService->getSiteConfiguration($sitePackageKey, 'ui.structure'); - foreach ($styleguideObjects as $prototypeName => &$styleguideObject) { - $styleguideObject['structure'] = $this->getStructureForPrototypeName($prototypeStructures, $prototypeName); + $structureSource = $this->configurationService->getSiteConfiguration($sitePackageKey, 'ui.structureSource'); + switch ($structureSource) { + case 'title': + foreach ($styleguideObjects as &$styleguideObject) { + $this->transformTitleStructure($prototypeStructures, $styleguideObject); + } + break; + + case 'prototypeName': + default: + foreach ($styleguideObjects as $prototypeName => &$styleguideObject) { + $styleguideObject['structure'] = $this->getStructureForPrototypeName($prototypeStructures, $prototypeName); + } + break; } $hiddenPrototypeNamePatterns = $this->configurationService->getSiteConfiguration($sitePackageKey, 'hiddenPrototypeNamePatterns'); @@ -181,7 +193,7 @@ function ($prototypeName) use ($pattern, $alwaysShowPrototypes) { } /** - * Find the matching structure for a prototype + * Find the matching structure for a prototype by prototypeName * * @param $prototypeStructures * @param $prototypeName @@ -201,4 +213,32 @@ protected function getStructureForPrototypeName($prototypeStructures, $prototype 'color' => 'white' ]; } + + /** + * Transform styleguideObject based on title structure + * + * @param $prototypeStructures + * @param $styleguideObject + */ + protected function transformTitleStructure($prototypeStructures, &$styleguideObject) + { + foreach ($prototypeStructures as $structure) { + $regex = sprintf('!%s!', $structure['match']); + if (preg_match($regex, $styleguideObject['title'], $matches)) { + $styleguideObject['structure'] = $structure; + + if (count($matches) > 1) { + $styleguideObject['title'] = $matches[1]; + } else { + $styleguideObject['title'] = preg_replace($regex, '', $styleguideObject['title']); + } + } + } + + $styleguideObject['structure'] = [ + 'label' => 'Other', + 'icon' => 'icon-question', + 'color' => 'white' + ]; + } } diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index f55e638..8056ba9 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -73,6 +73,8 @@ Sitegeist: icon: icon-file color: '#FFF' + structureSource: prototypeName + hiddenPrototypeNamePatterns: { } alwaysShowPrototypes: { }