Saving ckeditor5 with font color widget causes boolean error

Created on 16 July 2024, 4 months ago
Updated 14 August 2024, 3 months ago

Problem/Motivation

When adding the font color button on ckeditor5 and submit configuratiotn, an error occurs.

AssertionError: Schema errors: Array ( [editor.editor.id_does_not_matter:settings.plugins.ckeditor5_plugin_pack_font__font_color.use_default_colors] => variable type is integer but applied schema class is Drupal\Core\TypedData\Plugin\DataType\BooleanData ) in assert() (line 729 of core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php).

assert(, 'Schema errors: Array
(
    [editor.editor.id_does_not_matter:settings.plugins.ckeditor5_plugin_pack_font__font_color.use_default_colors] => variable type is integer but applied schema class is Drupal\Core\TypedData\Plugin\DataType\BooleanData
)
') (Line: 729)
Drupal\ckeditor5\Plugin\Editor\CKEditor5->validateConfigurationForm(Array, Object) (Line: 211)
editor_form_filter_admin_format_validate(Array, Object)
call_user_func_array('editor_form_filter_admin_format_validate', Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'filter_format_edit_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('filter_format_edit_form', Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('filter_format_edit_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Looking at modules/ckeditor5_plugin_pack_font/src/Plugin/CKEditor5Plugin/FontColor.php, $values['use_default_colors'] is an integer, and even with 1 as value, no boolean is returned.

public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
    $values = $form_state->cleanValues()->getValues();
    $this->configuration['colors'] = $values['custom_colors_wrapper'] ?? [];
    $this->configuration['use_default_colors'] = $values['use_default_colors'] ?? TRUE;
  }

Proposed resolution

Do not test it but cast it before setting it in configuration.

public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
    $values = $form_state->cleanValues()->getValues();
    $this->configuration['colors'] = $values['custom_colors_wrapper'] ?? [];
    $this->configuration['use_default_colors'] = (bool) $values['use_default_colors'];
  }
🐛 Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

🇫🇷France goz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024