Commit c63fd812 authored by Jacob Rockowitz's avatar Jacob Rockowitz
Browse files

Issue #3322552: CKEditor 5 support

parent 6513cb95
Loading
Loading
Loading
Loading
+0 −44
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  module:
    - editor
name: Webform
format: webform
weight: 100
roles:
  - authenticated
filters:
  filter_html:
    id: filter_html
    provider: filter
    status: true
    weight: -10
    settings:
      allowed_html: '<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <p> <br> <span> <img src alt height width data-entity-type data-entity-uuid data-align data-caption>'
      filter_html_help: false
      filter_html_nofollow: false
  filter_align:
    id: filter_align
    provider: filter
    status: true
    weight: 7
    settings: {  }
  filter_caption:
    id: filter_caption
    provider: filter
    status: true
    weight: 8
    settings: {  }
  filter_html_image_secure:
    id: filter_html_image_secure
    provider: filter
    status: true
    weight: 9
    settings: {  }
  editor_file_reference:
    id: editor_file_reference
    provider: editor
    status: true
    weight: 11
    settings: {  }
+11 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  module:
    - editor
name: Webform
format: webform
weight: 100
roles:
  - authenticated
filters: {  }
+25 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\webform\Utility\WebformElementHelper;
use Drupal\webform\Utility\WebformFormHelper;
use Drupal\webform\Utility\WebformXss;
@@ -100,7 +101,7 @@ class WebformHtmlEditor extends FormElement implements TrustedCallbackInterface
    // If #format or 'webform.settings.html_editor.element_format' is defined return
    // a 'text_format' element.
    $format = $element['#format'] ?: \Drupal::config('webform.settings')->get('html_editor.element_format');
    if ($format) {
    if ($format && FilterFormat::load($format)) {
      $element['value'] += [
        '#type' => 'text_format',
        '#format' => $format,
@@ -222,7 +223,28 @@ class WebformHtmlEditor extends FormElement implements TrustedCallbackInterface
      }
    }

    if ($format = \Drupal::config('webform.settings')->get('html_editor.element_format')) {
    $format = \Drupal::config('webform.settings')->get('html_editor.element_format');

    // Make sure the filter.module is installed.
    // This is only applicable for functional tests that do not install
    // the filter.module.
    if (!\Drupal::moduleHandler()->moduleExists('filter')) {
      $format = NULL;
    }

    // If the filter format is 'webform', check to see if it
    // has been customized with filter types, if has not been customized then
    // use the 'webform_html_editor_markup' template with the webform module's
    // allowed tags.
    if ($format === 'webform') {
      /** @var \Drupal\filter\FilterFormatInterface $format */
      $fiter_format = FilterFormat::load($format);
      if (empty($fiter_format) || empty($fiter_format->getFilterTypes())) {
        $format = NULL;
      }
    }

    if ($format) {
      return [
        '#type' => 'processed_text',
        '#text' => $text,
@@ -279,6 +301,7 @@ class WebformHtmlEditor extends FormElement implements TrustedCallbackInterface
   */
  public static function processTextFormat($element, FormStateInterface $form_state, &$complete_form) {
    // Remove the 'webform' text format from allowed formats.
    // This is needed because the webform text format DOES NOT filter HTML.
    if (empty($element['#allowed_formats'])) {
      $user = \Drupal::currentUser();
      $formats = filter_formats($user);
+12 −6
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ class WebformElementHtmlEditorTest extends WebformElementBrowserTestBase {
    // Check that CodeMirror is displayed when #format: FALSE.
    $assert_session->responseContains('<textarea data-drupal-selector="edit-webform-html-editor-codemirror-value" class="js-webform-codemirror webform-codemirror html required form-textarea" required="required" aria-required="true" data-webform-codemirror-mode="text/html" id="edit-webform-html-editor-codemirror-value" name="webform_html_editor_codemirror[value]" rows="5" cols="60">Hello &lt;b&gt;World!!!&lt;/b&gt;</textarea>');

    // Check that attributes are support by the default 'webform' filter format.
    $build = WebformHtmlEditor::checkMarkup('<p class="other">Some text</p>');
    $this->assertEquals(\Drupal::service('renderer')->renderPlain($build), '<p class="other">Some text</p>');

    // Disable HTML editor.
    $this->drupalGet('/admin/structure/webform/config/elements');
    $edit = ['html_editor[disabled]' => TRUE];
@@ -77,6 +81,10 @@ class WebformElementHtmlEditorTest extends WebformElementBrowserTestBase {
    $assert_session->responseNotContains('<textarea data-drupal-selector="edit-webform-html-editor-value-value" id="edit-webform-html-editor-value-value" name="webform_html_editor[value][value]" rows="5" cols="60" class="form-textarea required" required="required" aria-required="true">Hello &lt;b&gt;World!!!&lt;/b&gt;</textarea>');
    $assert_session->responseContains('<textarea data-drupal-selector="edit-webform-html-editor-value" class="js-webform-codemirror webform-codemirror html required form-textarea" required="required" aria-required="true" data-webform-codemirror-mode="text/html" id="edit-webform-html-editor-value" name="webform_html_editor[value]" rows="5" cols="60">Hello &lt;b&gt;World!!!&lt;/b&gt;</textarea>');

    // Check that attributes are support when the HTML editor is disabled.
    $build = WebformHtmlEditor::checkMarkup('<p class="other">Some text</p>');
    $this->assertEquals(\Drupal::service('renderer')->renderPlain($build), '<p class="other">Some text</p>');

    // Enable HTML editor and element text format.
    $this->drupalGet('/admin/structure/webform/config/elements');
    $edit = [
@@ -91,14 +99,14 @@ class WebformElementHtmlEditorTest extends WebformElementBrowserTestBase {
    $assert_session->responseNotContains('<textarea data-drupal-selector="edit-webform-html-editor-value" class="js-webform-codemirror webform-codemirror html required form-textarea" required="required" aria-required="true" data-webform-codemirror-mode="text/html" id="edit-webform-html-editor-value" name="webform_html_editor[value]" rows="5" cols="60">Hello &lt;b&gt;World!!!&lt;/b&gt;</textarea>');
    $assert_session->responseContains('<textarea data-drupal-selector="edit-webform-html-editor-value-value" id="edit-webform-html-editor-value-value" name="webform_html_editor[value][value]" rows="5" cols="60" class="form-textarea required" required="required" aria-required="true">Hello &lt;b&gt;World!!!&lt;/b&gt;</textarea>');

    // Check that attributes are NOT support by the basic_html filter format.
    $build = WebformHtmlEditor::checkMarkup('<p class="other">Some text</p>');
    $this->assertEquals(\Drupal::service('renderer')->renderPlain($build), '<p>Some text</p>');

    // Check that tidy removed <p> tags.
    $build = WebformHtmlEditor::checkMarkup('<p>Some text</p>');
    $this->assertEquals(\Drupal::service('renderer')->renderPlain($build), 'Some text');

    $build = WebformHtmlEditor::checkMarkup('<p class="other">Some text</p>');
    $this->assertEquals(\Drupal::service('renderer')->renderPlain($build), '<p>Some text</p>');

    $build = WebformHtmlEditor::checkMarkup('<p>Some text</p><p>More text</p>');
    $this->assertEquals(\Drupal::service('renderer')->renderPlain($build), '<p>Some text</p><p>More text</p>');

@@ -117,9 +125,7 @@ class WebformElementHtmlEditorTest extends WebformElementBrowserTestBase {
    $assert_session->responseContains('<textarea data-drupal-selector="edit-settings-body-custom-html-value-value" id="edit-settings-body-custom-html-value-value" name="settings[body_custom_html][value][value]" rows="5" cols="60" class="form-textarea">');

    // Enable mail text format.
    $edit = [
      'html_editor[mail_format]' => 'basic_html',
    ];
    $edit = ['html_editor[mail_format]' => 'basic_html'];
    $this->drupalGet('/admin/structure/webform/config/elements');
    $this->submitForm($edit, 'Save configuration');

Loading