You are here

public static function CKEditor5::validateSwitchingToCKEditor5 in Drupal 10

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

File

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

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 = Editor::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()));
    }
  }
}