From 1e48f5998ef4dbedd90aade6eabcbfbd3fb67e25 Mon Sep 17 00:00:00 2001 From: Trent Steel Date: Thu, 17 Aug 2023 15:27:43 +1000 Subject: [PATCH] Add option to prevent ckeditor.js from being automatically included (#120) --- .php-cs-fixer.dist.php | 2 +- DependencyInjection/Configuration.php | 1 + .../TrsteelCkeditorExtension.php | 1 + Form/Type/CkeditorType.php | 2 ++ .../views/Form/ckeditor_widget.html.twig | 5 +++- Tests/AppKernel.php | 2 +- Tests/Form/CkeditorTypeTest.php | 27 +++++++++++++++++++ phpstan.neon.dist | 1 + rector.php | 1 + 9 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 79fba70..33cdd50 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,7 +1,7 @@ exclude('tests/Fixtures') + ->exclude('var/cache') ->in(__DIR__); return (new PhpCsFixer\Config()) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6352a10..eff3dea 100755 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -21,6 +21,7 @@ public function getConfigTreeBuilder(): TreeBuilder $rootNode ->children() ->scalarNode('class')->defaultValue(CkeditorType::class)->end() + ->booleanNode('autoload_ckeditor_js')->defaultTrue()->end() ->arrayNode('html_purifier') ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/TrsteelCkeditorExtension.php b/DependencyInjection/TrsteelCkeditorExtension.php index 1b7462e..1c004bb 100755 --- a/DependencyInjection/TrsteelCkeditorExtension.php +++ b/DependencyInjection/TrsteelCkeditorExtension.php @@ -39,6 +39,7 @@ public function load(array $configs, ContainerBuilder $container): void $config['html_purifier']['config'] = array_merge(['Cache.SerializerPath' => '%kernel.cache_dir%'], $config['html_purifier']['config']); $container->setParameter('trsteel_ckeditor.form.type.class', $config['class']); + $container->setParameter('trsteel_ckeditor.autoload_ckeditor_js', $config['autoload_ckeditor_js']); $container->setParameter('trsteel_ckeditor.html_purifier.config', $config['html_purifier']['config']); $container->setParameter('trsteel_ckeditor.ckeditor.transformers', $config['transformers']); $container->setParameter('trsteel_ckeditor.ckeditor.toolbar', $config['toolbar']); diff --git a/Form/Type/CkeditorType.php b/Form/Type/CkeditorType.php index 5b86db1..0702e9f 100755 --- a/Form/Type/CkeditorType.php +++ b/Form/Type/CkeditorType.php @@ -99,6 +99,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): } } + $view->vars['autoload_ckeditor_js'] = $options['autoload_ckeditor_js']; $view->vars['toolbar'] = $toolbar; $view->vars['startup_outline_blocks'] = $options['startup_outline_blocks']; $view->vars['ui_color'] = $options['ui_color']; @@ -137,6 +138,7 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'required' => false, + 'autoload_ckeditor_js' => $this->container->getParameter('trsteel_ckeditor.autoload_ckeditor_js'), 'transformers' => $this->container->getParameter('trsteel_ckeditor.ckeditor.transformers'), 'toolbar' => $this->container->getParameter('trsteel_ckeditor.ckeditor.toolbar'), 'toolbar_groups' => $this->container->getParameter('trsteel_ckeditor.ckeditor.toolbar_groups'), diff --git a/Resources/views/Form/ckeditor_widget.html.twig b/Resources/views/Form/ckeditor_widget.html.twig index 12f27d0..9858da9 100644 --- a/Resources/views/Form/ckeditor_widget.html.twig +++ b/Resources/views/Form/ckeditor_widget.html.twig @@ -7,7 +7,10 @@ {% endautoescape %} - + {% if autoload_ckeditor_js %} + + {% endif %} +