Skip to content

Commit f7a85ee

Browse files
[FEATURE] Add event AfterYamlParseEvent
Introduces a new event that is fired after the YAML configuration of a content block is parsed and before it is processed.
1 parent b816508 commit f7a85ee

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
namespace TYPO3\CMS\ContentBlocks\Event;
19+
20+
final class AfterYamlParseEvent
21+
{
22+
/**
23+
* @param array<string, mixed> $contentBlocksConfiguration
24+
*/
25+
public function __construct(private array $contentBlocksConfiguration)
26+
{
27+
}
28+
29+
/**
30+
* @return array<string, mixed>
31+
*/
32+
public function getContentBlocksConfiguration(): array
33+
{
34+
return $this->contentBlocksConfiguration;
35+
}
36+
37+
/**
38+
* @param array<string, mixed> $contentBlocksConfiguration
39+
*/
40+
public function setContentBlocksConfiguration(array $contentBlocksConfiguration): void
41+
{
42+
$this->contentBlocksConfiguration = $contentBlocksConfiguration;
43+
}
44+
}

Classes/Loader/ContentBlockLoader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace TYPO3\CMS\ContentBlocks\Loader;
1919

20+
use Psr\EventDispatcher\EventDispatcherInterface;
2021
use Symfony\Component\DependencyInjection\Attribute\Autowire;
2122
use Symfony\Component\Finder\Finder;
2223
use TYPO3\CMS\ContentBlocks\Basics\BasicsLoader;
@@ -25,6 +26,7 @@
2526
use TYPO3\CMS\ContentBlocks\Definition\ContentType\ContentTypeIcon;
2627
use TYPO3\CMS\ContentBlocks\Definition\ContentType\PageIconSet;
2728
use TYPO3\CMS\ContentBlocks\Definition\Factory\UniqueIdentifierCreator;
29+
use TYPO3\CMS\ContentBlocks\Event\AfterYamlParseEvent;
2830
use TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry;
2931
use TYPO3\CMS\ContentBlocks\Schema\SimpleTcaSchemaFactory;
3032
use TYPO3\CMS\ContentBlocks\Service\Icon\ContentTypeIconResolverInput;
@@ -81,6 +83,7 @@ public function __construct(
8183
protected readonly AssetPublisher $assetPublisher,
8284
protected readonly ContentBlocksYamlParserInterface $contentBlocksYamlLoader,
8385
protected readonly SimpleTcaSchemaFactory $simpleTcaSchemaFactory,
86+
protected readonly EventDispatcherInterface $eventDispatcher,
8487
) {}
8588

8689
public function load(): ContentBlockRegistry
@@ -217,7 +220,9 @@ protected function parseConfigYaml(string $absoluteContentBlockPath, ContentType
217220
);
218221
}
219222
}
220-
return $config;
223+
$afterYamlParseEvent = new AfterYamlParseEvent($config);
224+
$this->eventDispatcher->dispatch($afterYamlParseEvent);
225+
return $afterYamlParseEvent->getContentBlocksConfiguration();
221226
}
222227

223228
protected function loadSingleContentBlock(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. include:: /Includes.rst.txt
2+
.. _psr14-events:
3+
4+
======
5+
Events
6+
======
7+
8+
Content Blocks provides PSR-14 events. See
9+
`Event Dispatcher <https://docs.typo3.org/permalink/t3coreapi:EventDispatcher>`__ for implementation.
10+
11+
Available events
12+
================
13+
14+
- :php:`\TYPO3\CMS\ContentBlocks\Event\AfterYamlParseEvent`

0 commit comments

Comments
 (0)