fluid-styleguide icon indicating copy to clipboard operation
fluid-styleguide copied to clipboard

Add new pre process component event

Open sascha-egerer opened this issue 7 months ago • 1 comments

Add a new event to modify a component before it is processed in the styleguide.

sascha-egerer avatar Apr 15 '25 11:04 sascha-egerer

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?

sascha-egerer avatar Apr 15 '25 11:04 sascha-egerer