Skip to content

Commit e313187

Browse files
committed
IBX-8784: Prevent initialization of RichText config as Twig global variable
1 parent 48f0e47 commit e313187

File tree

11 files changed

+35
-35
lines changed

11 files changed

+35
-35
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,6 @@ parameters:
100100
count: 1
101101
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
102102

103-
-
104-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:load\\(\\) has no return type specified\\.$#"
105-
count: 1
106-
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
107-
108-
-
109-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:load\\(\\) has parameter \\$configs with no value type specified in iterable type array\\.$#"
110-
count: 1
111-
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
112-
113103
-
114104
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:prepend\\(\\) has no return type specified\\.$#"
115105
count: 1
@@ -150,11 +140,6 @@ parameters:
150140
count: 1
151141
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
152142

153-
-
154-
message: "#^Parameter \\#1 \\$configuration of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\Extension\\:\\:processConfiguration\\(\\) expects Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface, Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface\\|null given\\.$#"
155-
count: 1
156-
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
157-
158143
-
159144
message: "#^Parameter \\#1 \\$filename of static method Symfony\\\\Component\\\\Yaml\\\\Yaml\\:\\:parseFile\\(\\) expects string, string\\|false given\\.$#"
160145
count: 2

src/bundle/DependencyInjection/Configuration.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ class Configuration extends SiteAccessConfiguration
1818
{
1919
public const CUSTOM_TAG_ATTRIBUTE_TYPES = ['number', 'string', 'boolean', 'choice', 'link'];
2020

21-
/**
22-
* Generates the configuration tree builder.
23-
*
24-
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
25-
*/
26-
public function getConfigTreeBuilder()
21+
public function getConfigTreeBuilder(): TreeBuilder
2722
{
2823
$treeBuilder = new TreeBuilder(IbexaFieldTypeRichTextExtension::EXTENSION_NAME);
2924

3025
$rootNode = $treeBuilder->getRootNode();
3126

3227
$sections = $rootNode->children();
28+
29+
$rootNode
30+
->children()
31+
->booleanNode('expose_config_as_global')->defaultFalse()->end()
32+
->end();
33+
3334
$this
3435
->addEnabledAttributeTypesSection($sections);
3536
$this

src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
use Symfony\Component\Config\FileLocator;
1515
use Symfony\Component\Config\Resource\FileResource;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17-
use Symfony\Component\DependencyInjection\Extension\Extension;
1817
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
1918
use Symfony\Component\DependencyInjection\Loader;
19+
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
2020
use Symfony\Component\Yaml\Yaml;
2121

2222
/**
2323
* Ibexa RichText Field Type Bundle extension.
2424
*/
25-
class IbexaFieldTypeRichTextExtension extends Extension implements PrependExtensionInterface
25+
class IbexaFieldTypeRichTextExtension extends ConfigurableExtension implements PrependExtensionInterface
2626
{
2727
public const EXTENSION_NAME = 'ibexa_fieldtype_richtext';
2828

@@ -45,15 +45,15 @@ public function getAlias()
4545
}
4646

4747
/**
48-
* Load Ibexa RichText Field Type Bundle configuration.
49-
*
50-
* @param array $configs
51-
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
52-
*
53-
* @throws \Exception
48+
* @param array<string, mixed> $mergedConfig
5449
*/
55-
public function load(array $configs, ContainerBuilder $container)
50+
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
5651
{
52+
$container->setParameter(
53+
'ibexa.field_type.richtext.expose_config_as_global',
54+
$mergedConfig['expose_config_as_global'],
55+
);
56+
5757
$settingsLoader = new Loader\YamlFileLoader(
5858
$container,
5959
new FileLocator(__DIR__ . '/../Resources/config/settings')
@@ -84,9 +84,7 @@ public function load(array $configs, ContainerBuilder $container)
8484
$loader->load('command.yaml');
8585
$loader->load('controller.yaml');
8686

87-
$configuration = $this->getConfiguration($configs, $container);
88-
$config = $this->processConfiguration($configuration, $configs);
89-
$this->registerRichTextConfiguration($config, $container);
87+
$this->registerRichTextConfiguration($mergedConfig, $container);
9088

9189
(new IbexaEncoreConfigurationDumper($container))->dumpCustomConfiguration(
9290
self::WEBPACK_CONFIG_NAMES

src/bundle/Resources/config/templating.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ services:
1111

1212
Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\YoutubeIdExtractorExtension: ~
1313

14-
Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\RichTextConfigurationExtension: ~
14+
Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\RichTextConfigurationExtension:
15+
arguments:
16+
$exposeGlobals: '%ibexa.field_type.richtext.expose_config_as_global%'

src/bundle/Templating/Twig/Extension/RichTextConfigurationExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ final class RichTextConfigurationExtension extends AbstractExtension implements
2222
/** @var \Ibexa\Contracts\FieldTypeRichText\Configuration\ProviderService */
2323
private $configurationProvider;
2424

25-
public function __construct(ProviderService $configurationProvider)
25+
private bool $exposeGlobals;
26+
27+
public function __construct(ProviderService $configurationProvider, bool $exposeGlobals = false)
2628
{
2729
$this->configurationProvider = $configurationProvider;
30+
$this->exposeGlobals = $exposeGlobals;
2831
}
2932

3033
public function getGlobals(): array
3134
{
35+
if (!$this->exposeGlobals) {
36+
return [];
37+
}
38+
3239
$config = $this->configurationProvider->getConfiguration();
3340

3441
return [

tests/bundle/DependencyInjection/Configuration/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function providerForTestProcessingConfiguration(): array
7474
'custom_tags' => [],
7575
'custom_styles' => [],
7676
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
77+
'expose_config_as_global' => false,
7778
],
7879
],
7980
'Alloy editor configs from multiple sources' => [
@@ -113,6 +114,7 @@ public function providerForTestProcessingConfiguration(): array
113114
'custom_tags' => [],
114115
'custom_styles' => [],
115116
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
117+
'expose_config_as_global' => false,
116118
],
117119
],
118120
];

tests/bundle/DependencyInjection/Fixtures/custom_tags/output/000-attribute-type-number.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ enabled_attribute_types:
1515
- 'boolean'
1616
- 'choice'
1717
- 'link'
18+
expose_config_as_global: false

tests/bundle/DependencyInjection/Fixtures/custom_tags/output/001-attribute-type-string.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ enabled_attribute_types:
1515
- 'boolean'
1616
- 'choice'
1717
- 'link'
18+
expose_config_as_global: false

tests/bundle/DependencyInjection/Fixtures/custom_tags/output/002-attribute-type-boolean.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ enabled_attribute_types:
1515
- 'boolean'
1616
- 'choice'
1717
- 'link'
18+
expose_config_as_global: false

tests/bundle/DependencyInjection/Fixtures/custom_tags/output/003-attribute-type-choice.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ enabled_attribute_types:
1616
- 'boolean'
1717
- 'choice'
1818
- 'link'
19+
expose_config_as_global: false

0 commit comments

Comments
 (0)