Loading config/schema/webform.settings.schema.yml +11 −1 Original line number Diff line number Diff line Loading @@ -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' Loading src/Plugin/WebformElementBase.php +10 −0 Original line number Diff line number Diff line Loading @@ -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, Loading tests/src/Functional/Element/WebformElementFormatTest.php +13 −1 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -33,6 +33,8 @@ class WebformElementFormatTest extends WebformElementBrowserTestBase { * Tests element format. */ public function testFormat() { $assert_session = $this->assertSession(); $this->drupalLogin($this->rootUser); /* ********************************************************************** */ Loading Loading @@ -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') Loading @@ -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'); } /** Loading Loading
config/schema/webform.settings.schema.yml +11 −1 Original line number Diff line number Diff line Loading @@ -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' Loading
src/Plugin/WebformElementBase.php +10 −0 Original line number Diff line number Diff line Loading @@ -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, Loading
tests/src/Functional/Element/WebformElementFormatTest.php +13 −1 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -33,6 +33,8 @@ class WebformElementFormatTest extends WebformElementBrowserTestBase { * Tests element format. */ public function testFormat() { $assert_session = $this->assertSession(); $this->drupalLogin($this->rootUser); /* ********************************************************************** */ Loading Loading @@ -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') Loading @@ -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'); } /** Loading