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

Issue #3252605 by jrockowitz, pvbergen: Webform element edit form don't...

Issue #3252605 by jrockowitz, pvbergen: Webform element edit form don't respect an element's default format settings
parent 3dff9116
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -435,8 +435,18 @@ webform.settings:
          type: boolean
          label: 'Immediately deleted temporary managed webform submission files'
    format:
      type: ignore
      type: sequence
      label: 'Format default settings'
      sequence:
        type: mapping
        label: 'Element type'
        mapping:
          item:
            type: string
            label: 'Default item format'
          items:
            type: string
            label: 'Default items format'
    mail:
      type: mapping
      label: 'Email default settings'
+10 −0
Original line number Diff line number Diff line
@@ -313,6 +313,16 @@ class WebformElementBase extends PluginBase implements WebformElementInterface,
    if (!isset($this->defaultProperties)) {
      $properties = $this->defineDefaultProperties();
      $definition = $this->getPluginDefinition();
      // Apply default format settings to element edit form properties.
      // This approach prevents having to refactor how default formats
      // are handled.
      $config = $this->configFactory->get('webform.settings');
      if (isset($properties['format'])) {
        $properties['format'] = $config->get('format.' . $this->getPluginId() . '.item') ?? $properties['format'];
      }
      if (isset($properties['format_items'])) {
        $properties['format_items'] = $config->get('format.' . $this->getPluginId() . '.items') ?? $properties['format_items'];
      }
      \Drupal::moduleHandler()->alter(
        'webform_element_default_properties',
        $properties,
+13 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ class WebformElementFormatTest extends WebformElementBrowserTestBase {
   *
   * @var array
   */
  public static $modules = ['node', 'taxonomy', 'file', 'webform', 'webform_image_select'];
  public static $modules = ['node', 'taxonomy', 'file', 'webform', 'webform_ui', 'webform_image_select'];

  /**
   * Webforms to load.
@@ -33,6 +33,8 @@ class WebformElementFormatTest extends WebformElementBrowserTestBase {
   * Tests element format.
   */
  public function testFormat() {
    $assert_session = $this->assertSession();

    $this->drupalLogin($this->rootUser);

    /* ********************************************************************** */
@@ -268,6 +270,11 @@ class WebformElementFormatTest extends WebformElementBrowserTestBase {
      $this->assertStringContainsString($value, $body, new FormattableMarkup('Found @value', ['@value' => $value]));
    }

    // Check that the element edit form uses the default format.
    $this->drupalGet('/admin/structure/webform/manage/test_element_format_token/element/checkboxes/edit');
    $assert_session->fieldValueEquals('properties[format]', 'value');
    $assert_session->fieldValueEquals('properties[format_items]', 'comma');

    // Check element default format item global setting.
    \Drupal::configFactory()->getEditable('webform.settings')
      ->set('format.checkboxes.item', 'raw')
@@ -281,6 +288,11 @@ class WebformElementFormatTest extends WebformElementBrowserTestBase {
      ->save();
    $body = $this->getMessageBody($webform_format_token_submission, 'email_text');
    $this->assertStringContainsString("default:\n1, 2, and 3", $body);

    // Check that the element edit form uses the overridden default format.
    $this->drupalGet('/admin/structure/webform/manage/test_element_format_token/element/checkboxes/edit');
    $assert_session->fieldValueEquals('properties[format]', 'raw');
    $assert_session->fieldValueEquals('properties[format_items]', 'and');
  }

  /**