function CKEditor5::validateSwitchingToCKEditor5

Same name in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::validateSwitchingToCKEditor5()
  2. 10 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::validateSwitchingToCKEditor5()

Validate callback to inform the user of CKEditor 5 compatibility problems.

File

core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php, line 505

Class

CKEditor5
Defines a CKEditor 5-based text editor for Drupal.

Namespace

Drupal\ckeditor5\Plugin\Editor

Code

public static function validateSwitchingToCKEditor5(array $form, FormStateInterface $form_state) : void {
    if (!$form_state->get('ckeditor5_is_active') && $form_state->get('ckeditor5_is_selected')) {
        $minimal_ckeditor5_editor = EditorEntity::create([
            'format' => NULL,
            'editor' => 'ckeditor5',
        ]);
        $submitted_filter_format = CKEditor5::getSubmittedFilterFormat($form_state);
        $fundamental_incompatibilities = CKEditor5::validatePair($minimal_ckeditor5_editor, $submitted_filter_format, FALSE);
        foreach ($fundamental_incompatibilities as $violation) {
            // If the violation uses the nonAllowedElementsMessage template, it can
            // be skipped because this is a violation that automatically fixed
            // within SmartDefaultSettings, but SmartDefaultSettings does not
            // execute until this validator passes.
            if ($violation->getMessageTemplate() === $violation->getConstraint()->nonAllowedElementsMessage) {
                continue;
            }
            // @codingStandardsIgnoreLine
            $form_state->setErrorByName('editor][editor', t($violation->getMessageTemplate(), $violation->getParameters()));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.