diff --git a/src/bundle/DependencyInjection/Configuration.php b/src/bundle/DependencyInjection/Configuration.php index e4fa52b2..d03a0aad 100644 --- a/src/bundle/DependencyInjection/Configuration.php +++ b/src/bundle/DependencyInjection/Configuration.php @@ -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 diff --git a/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php b/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php index 957e42d7..2ebbc298 100644 --- a/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php +++ b/src/bundle/DependencyInjection/IbexaFieldTypeRichTextExtension.php @@ -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'; @@ -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 $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') @@ -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 diff --git a/src/bundle/Resources/config/templating.yaml b/src/bundle/Resources/config/templating.yaml index 42d26faf..e6831569 100644 --- a/src/bundle/Resources/config/templating.yaml +++ b/src/bundle/Resources/config/templating.yaml @@ -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%' diff --git a/src/bundle/Templating/Twig/Extension/RichTextConfigurationExtension.php b/src/bundle/Templating/Twig/Extension/RichTextConfigurationExtension.php index e85b4013..5484a5af 100644 --- a/src/bundle/Templating/Twig/Extension/RichTextConfigurationExtension.php +++ b/src/bundle/Templating/Twig/Extension/RichTextConfigurationExtension.php @@ -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 [