Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions Classes/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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'
];
}
}
2 changes: 2 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Sitegeist:
icon: icon-file
color: '#FFF'

structureSource: prototypeName

hiddenPrototypeNamePatterns: { }
alwaysShowPrototypes: { }

Expand Down