Commit 3b3cbc0d authored by Jacob Rockowitz's avatar Jacob Rockowitz Committed by Jacob Rockowitz
Browse files

Issue #2917021 by jrockowitz: Extra text format option for email texts

parent a3972c87
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -72,8 +72,9 @@ class WebformHtmlEditor extends FormElement {
      $element['value']['#required'] = $element['#required'];
    }

    // If HTML disabled return simple CodeMirror HTML editor.
    $disabled = \Drupal::config('webform.settings')->get('html_editor.disabled') ?: $element['#format'];
    // If HTML disabled and no #format is specified return simple CodeMirror
    // HTML editor.
    $disabled = \Drupal::config('webform.settings')->get('html_editor.disabled') ?: ($element['#format'] ===  FALSE);
    if ($disabled) {
      $element['value'] += [
        '#type' => 'webform_codemirror',
@@ -83,8 +84,9 @@ class WebformHtmlEditor extends FormElement {
      return $element;
    }

    // If #context and format is defined return 'text_format' element.
    $format = \Drupal::config('webform.settings')->get('html_editor.format') ?: $element['#format'];
    // If #format or 'webform.settings.html_editor.format' is defined return
    // a 'text_format' element.
    $format = $element['#format'] ?: \Drupal::config('webform.settings')->get('html_editor.format');
    if ($format) {
      $element['value'] += [
        '#type' => 'text_format',
+6 −0
Original line number Diff line number Diff line
@@ -84,6 +84,12 @@ abstract class WebformHandlerFormBase extends FormBase {
      }
    }

    // Add meta data to webform handler form.
    // This information makes it a little easier to alter a handler's form.
    $form['#webform_id']  = $this->webform->id();
    $form['#webform_handler_id'] = $this->webformHandler->getHandlerId();
    $form['#webform_handler_plugin_id'] = $this->webformHandler->getPluginId();

    $request = $this->getRequest();

    $form['description'] = [
+5 −1
Original line number Diff line number Diff line
@@ -42,10 +42,14 @@ class WebformElementHtmlEditorTest extends WebformTestBase {
  public function testHtmlEditor() {
    $this->drupalLogin($this->rootUser);

    // Check that HTML editor is enabled.
    $this->drupalGet('webform/test_element_html_editor');

    // Check that HTML editor is enabled.
    $this->assertRaw('<textarea class="js-html-editor form-textarea resize-vertical" data-drupal-selector="edit-webform-html-editor-value" 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 CodeMirror is displayed when #format: FALSE.
    $this->assertRaw('<textarea data-drupal-selector="edit-webform-html-editor-codemirror-value" class="js-webform-codemirror webform-codemirror html form-textarea resize-vertical" 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>');

    // Disable HTML editor.
    $this->drupalPostForm('admin/structure/webform/config/elements', ['html_editor[disabled]' => TRUE], t('Save configuration'));

+5 −0
Original line number Diff line number Diff line
@@ -27,6 +27,11 @@ elements: |
    '#title': 'webform_html_editor (format)'
    '#default_value': 'Hello <b>World!!!</b>'
    '#format': 'basic_html'
  webform_html_editor_codemirror:
    '#type': webform_html_editor
    '#title': 'webform_html_editor_codemirror (none)'
    '#default_value': 'Hello <b>World!!!</b>'
    '#format': false
css: ''
javascript: ''
settings: