Skip to content

Commit

Permalink
IBX-8784: Prevent initialization of RichText config as Twig global va…
Browse files Browse the repository at this point in the history
…riable
  • Loading branch information
Steveb-p committed Aug 26, 2024
1 parent 48f0e47 commit f28930b
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 35 deletions.
17 changes: 2 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ parameters:
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:load\\(\\) has no return type specified\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:load\\(\\) has parameter \\$configs with no value type specified in iterable type array\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Method Ibexa\\\\Bundle\\\\FieldTypeRichText\\\\DependencyInjection\\\\IbexaFieldTypeRichTextExtension\\:\\:prepend\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -150,11 +140,6 @@ parameters:
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
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\\.$#"
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php

-
message: "#^Parameter \\#1 \\$filename of static method Symfony\\\\Component\\\\Yaml\\\\Yaml\\:\\:parseFile\\(\\) expects string, string\\|false given\\.$#"
count: 2
Expand Down Expand Up @@ -1314,10 +1299,12 @@ parameters:
message: "#^Cannot access property \\$id on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php

-
message: "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php

-
message: "#^Cannot access property \\$value on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 1
Expand Down
13 changes: 7 additions & 6 deletions src/bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ class Configuration extends SiteAccessConfiguration
{
public const CUSTOM_TAG_ATTRIBUTE_TYPES = ['number', 'string', 'boolean', 'choice', 'link'];

/**
* Generates the configuration tree builder.
*
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(IbexaFieldTypeRichTextExtension::EXTENSION_NAME);

$rootNode = $treeBuilder->getRootNode();

$sections = $rootNode->children();

$rootNode
->children()
->booleanNode('expose_config_as_global')->defaultFalse()->end()
->end();

$this
->addEnabledAttributeTypesSection($sections);
$this
Expand Down
22 changes: 10 additions & 12 deletions src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
use Symfony\Component\Yaml\Yaml;

/**
* Ibexa RichText Field Type Bundle extension.
*/
class IbexaFieldTypeRichTextExtension extends Extension implements PrependExtensionInterface
class IbexaFieldTypeRichTextExtension extends ConfigurableExtension implements PrependExtensionInterface
{
public const EXTENSION_NAME = 'ibexa_fieldtype_richtext';

Expand All @@ -45,15 +45,15 @@ public function getAlias()
}

/**
* Load Ibexa RichText Field Type Bundle configuration.
*
* @param array $configs
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*
* @throws \Exception
* @param array<string, mixed> $mergedConfig
*/
public function load(array $configs, ContainerBuilder $container)
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
{
$container->setParameter(
'ibexa.field_type.richtext.expose_config_as_global',
$mergedConfig['expose_config_as_global'],
);

$settingsLoader = new Loader\YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config/settings')
Expand Down Expand Up @@ -84,9 +84,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('command.yaml');
$loader->load('controller.yaml');

$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$this->registerRichTextConfiguration($config, $container);
$this->registerRichTextConfiguration($mergedConfig, $container);

(new IbexaEncoreConfigurationDumper($container))->dumpCustomConfiguration(
self::WEBPACK_CONFIG_NAMES
Expand Down
4 changes: 3 additions & 1 deletion src/bundle/Resources/config/templating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ services:

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

Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\RichTextConfigurationExtension: ~
Ibexa\Bundle\FieldTypeRichText\Templating\Twig\Extension\RichTextConfigurationExtension:
arguments:
$exposeGlobals: '%ibexa.field_type.richtext.expose_config_as_global%'
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ final class RichTextConfigurationExtension extends AbstractExtension implements
/** @var \Ibexa\Contracts\FieldTypeRichText\Configuration\ProviderService */
private $configurationProvider;

public function __construct(ProviderService $configurationProvider)
private bool $exposeGlobals;

public function __construct(ProviderService $configurationProvider, bool $exposeGlobals = false)
{
$this->configurationProvider = $configurationProvider;
$this->exposeGlobals = $exposeGlobals;
}

public function getGlobals(): array
{
if (!$this->exposeGlobals) {
return [];
}

$config = $this->configurationProvider->getConfiguration();

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function providerForTestProcessingConfiguration(): array
'custom_tags' => [],
'custom_styles' => [],
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
'expose_config_as_global' => false,
],
],
'Alloy editor configs from multiple sources' => [
Expand Down Expand Up @@ -113,6 +114,7 @@ public function providerForTestProcessingConfiguration(): array
'custom_tags' => [],
'custom_styles' => [],
'enabled_attribute_types' => ['number', 'string', 'boolean', 'choice', 'link'],
'expose_config_as_global' => false,
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: false
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: false
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: false
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: false
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ enabled_attribute_types:
- 'boolean'
- 'choice'
- 'link'
expose_config_as_global: false

0 comments on commit f28930b

Please sign in to comment.