Skip to content

Commit

Permalink
Add option to prevent ckeditor.js from being automatically included (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
trsteel88 authored Aug 17, 2023
1 parent 003b707 commit 1e48f59
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$finder = PhpCsFixer\Finder::create()
//->exclude('tests/Fixtures')
->exclude('var/cache')
->in(__DIR__);

return (new PhpCsFixer\Config())
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/TrsteelCkeditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
2 changes: 2 additions & 0 deletions Form/Type/CkeditorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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'),
Expand Down
5 changes: 4 additions & 1 deletion Resources/views/Form/ckeditor_widget.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
{% endautoescape %}
</script>

<script type="text/javascript" src="{{ asset(base_path ~ 'ckeditor.js') }}"></script>
{% if autoload_ckeditor_js %}
<script type="text/javascript" src="{{ asset(base_path ~ 'ckeditor.js') }}"></script>
{% endif %}

<script type="text/javascript">
{% autoescape false %}
{% set plugins = '' %}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function registerBundles(): iterable
return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__.'/Resources/config/config.yml');
}
Expand Down
27 changes: 27 additions & 0 deletions Tests/Form/CkeditorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ public function get($serviceId)
return self::$kernel->getContainer()->get($serviceId);
}

/**
* Check the default required property.
*/
public function testDefaultAutoloadCkeditorJs()
{
$form = $this->factory->create($this->formType);
$view = $form->createView();
$autoloadCkeditorJs = $view->vars['autoload_ckeditor_js'];

$this->assertTrue($autoloadCkeditorJs);
}

/**
* Check the required property.
*/
public function testAutoloadCkeditorJs()
{
$form = $this->factory->create($this->formType, null, [
'autoload_ckeditor_js' => true,
]);

$view = $form->createView();
$autoloadCkeditorJs = $view->vars['autoload_ckeditor_js'];

$this->assertSame($autoloadCkeditorJs, true);
}

/**
* Check the default required property.
*/
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ parameters:
excludePaths:
- vendor
- Tests
- var/cache

checkGenericClassInNonGenericObjectType: false
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$rectorConfig->skip([
__DIR__.'/vendor',
__DIR__.'/Tests',
__DIR__.'/var',
]);

$rectorConfig->importNames();
Expand Down

0 comments on commit 1e48f59

Please sign in to comment.