Commit 4629a1b2 authored by Jacob Rockowitz's avatar Jacob Rockowitz
Browse files

Issue #3322552: CKEditor 5 support

parent d2014b1c
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies:
  config:
    - filter.format.webform
  module:
    - ckeditor
format: webform
editor: ckeditor
settings:
  toolbar:
    rows:
      -
        -
          name: Formatting
          items:
            - Format
            - Bold
            - Italic
            - Superscript
            - Subscript
        -
          name: Media
          items:
            - SpecialChar
        -
          name: Linking
          items:
            - DrupalLink
            - DrupalUnlink
        -
          name: Lists
          items:
            - NumberedList
            - BulletedList
        -
          name: Indentation
          items:
            - Outdent
            - Indent
        -
          name: 'Block Formatting'
          items:
            - Blockquote
        -
          name: Tools
          items:
            - Source
            - Maximize
  plugins: {  }
+44 −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:
  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: {  }
+2 −2
Original line number Diff line number Diff line
@@ -197,8 +197,8 @@ element:
    password_confirm: password_confirm
html_editor:
  disabled: false
  element_format: ''
  mail_format: ''
  element_format: webform
  mail_format: webform
  tidy: true
  make_unused_managed_files_temporary: true
file:
+63 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\webform\Element;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\webform\Utility\WebformElementHelper;
use Drupal\webform\Utility\WebformFormHelper;
use Drupal\webform\Utility\WebformXss;
@@ -14,7 +15,7 @@ use Drupal\webform\Utility\WebformXss;
 *
 * @FormElement("webform_html_editor")
 */
class WebformHtmlEditor extends FormElement {
class WebformHtmlEditor extends FormElement implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
@@ -104,6 +105,7 @@ class WebformHtmlEditor extends FormElement {
        '#type' => 'text_format',
        '#format' => $format,
        '#allowed_formats' => [$format],
        '#webform_html_editor' => TRUE,
        // Do not allow the text format value to be cleared when the text format
        // is hidden via #states. We must use a wrapper <div> because
        // The TextFormat element does not support #attributes.
@@ -279,4 +281,64 @@ class WebformHtmlEditor extends FormElement {
    return Xss::filter($text, static::getAllowedTags());
  }

  /* ************************************************************************ */
  // Text format callbacks.
  // @see \webform_element_info_alter()
  /* ************************************************************************ */

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return ['preRenderTextFormat'];
  }

  /**
   * Process text format.
   *
   * @param array $element
   *   An associative array containing the properties and children of the
   *   radios or checkboxes element.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   * @param array $complete_form
   *   The complete webform structure.
   *
   * @return array
   *   The processed element.
   */
  public static function processTextFormat($element, FormStateInterface $form_state, &$complete_form) {
    // Remove the 'webform' text format from allowed formats.
    if (empty($element['#allowed_formats'])) {
      $user = \Drupal::currentUser();
      $formats = filter_formats($user);
      if (isset($formats['webform'])) {
        unset($formats['webform']);
        $element['#allowed_formats'] = array_keys($formats);
      }
    }
    return $element;
  }

  /**
   * Prepares a #type 'text_format'.
   *
   * @param array $element
   *   An associative array containing the properties of the element.
   *
   * @return array
   *   The $element with prepared variables ready for theme_element().
   */
  public static function preRenderTextFormat(array $element) {
    // Remove guidelines and help from the 'webform_html_editor'.
    // @see \Drupal\webform\Element\WebformHtmlEditor::processWebformHtmlEditor
    if (!empty($element['#webform_html_editor'])) {
      unset(
        $element['format']['guidelines'],
        $element['format']['help']
      );
    }
    return $element;
  }

}
+2 −21
Original line number Diff line number Diff line
@@ -210,8 +210,8 @@ class WebformAdminConfigElementsForm extends WebformAdminConfigBaseForm {
      '#type' => 'select',
      '#title' => $this->t('Element text format'),
      '#description' => $this->t('Leave blank to use the custom and recommended Webform specific HTML editor.'),
      '#empty_option' => $this->t('- None -'),
      '#options' => $format_options,
      '#required' => TRUE,
      '#default_value' => $config->get('html_editor.element_format'),
      '#parents' => ['html_editor', 'element_format'],
    ];
@@ -219,15 +219,10 @@ class WebformAdminConfigElementsForm extends WebformAdminConfigBaseForm {
      '#type' => 'select',
      '#title' => $this->t('Mail text format'),
      '#description' => $this->t('Leave blank to use the custom and recommended Webform specific HTML editor.'),
      '#empty_option' => $this->t('- None -'),
      '#options' => $format_options,
      '#required' => TRUE,
      '#default_value' => $config->get('html_editor.mail_format'),
      '#parents' => ['html_editor', 'mail_format'],
      '#states' => [
        'visible' => [
          ':input[name="html_editor[disabled]"]' => ['checked' => FALSE],
        ],
      ],
    ];
    $form['html_editor']['format_container']['make_unused_managed_files_temporary'] = [
      '#type' => 'checkbox',
@@ -236,26 +231,12 @@ class WebformAdminConfigElementsForm extends WebformAdminConfigBaseForm {
      '#return_value' => TRUE,
      '#default_value' => $config->get('html_editor.make_unused_managed_files_temporary'),
      '#parents' => ['html_editor', 'make_unused_managed_files_temporary'],
      '#states' => [
        'visible' => [
          [':input[name="html_editor[element_format]"]' => ['!value' => '']],
          'or',
          [':input[name="html_editor[mail_format]"]' => ['!value' => '']],
        ],
      ],
    ];
    $form['html_editor']['format_container']['warning_message'] = [
      '#type' => 'webform_message',
      '#message_message' => $this->t('Files uploaded via the CKEditor file dialog to webform elements, settings, and configuration will not be exportable.') . '<br/>' .
        '<strong>' . $this->t('All files must be uploaded to your production environment and then copied to development and local environment.') . '</strong>',
      '#message_type' => 'warning',
      '#states' => [
        'visible' => [
          [':input[name="html_editor[element_format]"]' => ['!value' => '']],
          'or',
          [':input[name="html_editor[mail_format]"]' => ['!value' => '']],
        ],
      ],
      '#message_close' => TRUE,
      '#message_storage' => WebformMessage::STORAGE_SESSION,
    ];
Loading