fluid-styleguide
fluid-styleguide copied to clipboard
Add new pre process component event
Add a new event to modify a component before it is processed in the styleguide.
I use this to define "settings" via fixtures:
<?php
declare(strict_types = 1);
namespace Flowd\XXX\EventListener;
use Sitegeist\FluidStyleguide\Event\PreProcessComponentViewEvent;
use SMS\FluidComponents\Utility\ComponentSettings;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Utility\ArrayUtility;
#[AsEventListener]
class StyleguidePreProcessComponentViewEvent
{
public function __construct(private readonly ComponentSettings $componentSettings)
{
}
public function __invoke(PreProcessComponentViewEvent $event): void
{
$fixtureData = $event->component->getFixture($event->fixtureName)->getData();
$settings = ArrayUtility::flattenPlain($fixtureData['settings'] ?? []);
foreach ($settings as $settingPath => $settingValue) {
$this->componentSettings->set($settingPath, $settingValue);
}
}
}
Maybe this should also be added to the extension itself? Opinions?