Verified Commit c4340b27 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3505641 by berdir, smustgrave: Simplify...

Issue #3505641 by berdir, smustgrave: Simplify ckeditor5_module_implements_alter() in favor of checking for ckeditor5 in media module

(cherry picked from commit f7e7f3ef)
parent 3d827c8a
Loading
Loading
Loading
Loading
Loading
+2 −14
Original line number Diff line number Diff line
@@ -106,14 +106,11 @@ public function theme() : array {
   *
   * This module's implementation of form_filter_format_form_alter() must
   * happen after the editor module's implementation, as that implementation
   * adds the active editor to $form_state. It must also happen after the media
   * module's implementation so media_filter_format_edit_form_validate can be
   * removed from the validation chain, as that validator is not needed with
   * CKEditor 5 and will trigger a false error.
   * adds the active editor to $form_state.
   */
  #[Hook('form_filter_format_form_alter',
    order: new OrderAfter(
      modules: ['editor', 'media'],
      modules: ['editor'],
    )
  )]
  public function formFilterFormatFormAlter(array &$form, FormStateInterface $form_state, $form_id) : void {
@@ -137,15 +134,6 @@ public function formFilterFormatFormAlter(array &$form, FormStateInterface $form
          by the CKEditor 5 configuration. Manually removing tags would break
          enabled functionality, and any manually added tags would be removed by
          CKEditor 5 on render.');
        // The media_filter_format_edit_form_validate validator is not needed
        // with CKEditor 5 as it exists to enforce the inclusion of specific
        // allowed tags that are added automatically by CKEditor 5. The
        // validator is removed so it does not conflict with the automatic
        // addition of those allowed tags.
        $key = array_search('media_filter_format_edit_form_validate', $form['#validate']);
        if ($key !== FALSE) {
          unset($form['#validate'][$key]);
        }
      }
    }
    // Override the AJAX callbacks for changing editors, so multiple areas of
+12 −4
Original line number Diff line number Diff line
@@ -221,9 +221,13 @@ public function entityTypeAlter(array &$entity_types) : void {
  #[Hook('form_filter_format_edit_form_alter')]
  public function formFilterFormatEditFormAlter(array &$form, FormStateInterface $form_state, $form_id) : void {
    // Add an additional validate callback so we can ensure the order of filters
    // is correct.
    // is correct, this is not necessary when using ckeditor5 since allowed tags
    // are added automatically by CKEditor 5. The validator would conflict with
    // the automatic addition of those allowed tags.
    if ($form_state->getValue('editor') !== 'ckeditor5') {
      $form['#validate'][] = 'media_filter_format_edit_form_validate';
    }
  }

  /**
   * Implements hook_form_FORM_ID_alter().
@@ -231,9 +235,13 @@ public function formFilterFormatEditFormAlter(array &$form, FormStateInterface $
  #[Hook('form_filter_format_add_form_alter')]
  public function formFilterFormatAddFormAlter(array &$form, FormStateInterface $form_state, $form_id) : void {
    // Add an additional validate callback so we can ensure the order of filters
    // is correct.
    // is correct, this is not necessary when using ckeditor5 since allowed tags
    // are added automatically by CKEditor 5. The validator would conflict with
    // the automatic addition of those allowed tags.
    if ($form_state->getValue('editor') !== 'ckeditor5') {
      $form['#validate'][] = 'media_filter_format_edit_form_validate';
    }
  }

  /**
   * Implements hook_field_widget_single_element_form_alter().