diff --git a/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconFormatter.php b/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconFormatter.php index 3a92ca51efffcb9514876daed5d9fb7296e9f86e..59323d7e69c527959deb04c9db7d1474c90017c6 100644 --- a/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconFormatter.php +++ b/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconFormatter.php @@ -113,6 +113,10 @@ class IconFormatter extends FormatterBase implements ContainerFactoryPluginInter public function settingsForm(array $form, FormStateInterface $form_state): array { $elements = parent::settingsForm($form, $form_state); + $icon_settings = $this->getSetting('icon_settings') ?? []; + + $this->pluginManagerIconPack->getExtractorPluginForms($elements, $form_state, $icon_settings, [], TRUE); + // @todo get widget settings to know if field has extractor settings enabled. $elements['icon_pack_notice'] = [ '#type' => 'html_tag', @@ -121,10 +125,6 @@ class IconFormatter extends FormatterBase implements ContainerFactoryPluginInter '#attributes' => ['class' => ['description']], ]; - $icon_settings = $this->getSetting('icon_settings') ?? []; - - $this->pluginManagerIconPack->getExtractorPluginForms($elements, $form_state, $icon_settings); - // Placeholder to get all settings serialized as the form keys are dynamic // and based on icon pack definition options. // @todo probably change to #element_submit when available in diff --git a/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconLinkFormatter.php b/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconLinkFormatter.php index 24a68378b8547ac0b142fa3b1aba9433df6a4029..af6e77add256c751a85c4f130ef012bf125eda3f 100644 --- a/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconLinkFormatter.php +++ b/modules/ui_icons_field/src/Plugin/Field/FieldFormatter/IconLinkFormatter.php @@ -145,7 +145,7 @@ class IconLinkFormatter extends LinkFormatter { $icon_settings = $this->getSetting('icon_settings') ?? []; - $this->pluginManagerIconPack->getExtractorPluginForms($elements, $form_state, $icon_settings); + $this->pluginManagerIconPack->getExtractorPluginForms($elements, $form_state, $icon_settings, [], TRUE); // Placeholder to get all settings serialized as the form keys are dynamic // and based on icon pack definition options. diff --git a/src/Form/IconExtractorSettingsForm.php b/src/Form/IconExtractorSettingsForm.php index b201be2ba92dde612796429c3b813c496974b2bf..60b6f0505fe083b0a3ed81711e631f0e08c34d4f 100644 --- a/src/Form/IconExtractorSettingsForm.php +++ b/src/Form/IconExtractorSettingsForm.php @@ -94,7 +94,6 @@ class IconExtractorSettingsForm { 'size' => '#size', 'maxlength' => '#maxlength', 'pattern' => '#pattern', - 'required' => '#required', 'prefix' => '#field_prefix', 'suffix' => '#field_suffix', 'placeholder' => '#placeholder', diff --git a/src/Plugin/IconPackManager.php b/src/Plugin/IconPackManager.php index 9acead6341520436ed37b34f9fdf7fecc718a8e7..85124c1d22bc211c950ac8f9eeab826f5140f35c 100644 --- a/src/Plugin/IconPackManager.php +++ b/src/Plugin/IconPackManager.php @@ -246,7 +246,7 @@ class IconPackManager extends DefaultPluginManager implements IconPackManagerInt /** * {@inheritdoc} */ - public function getExtractorPluginForms(array &$form, FormStateInterface $form_state, array $default_settings = [], array $allowed_icon_pack = []): void { + public function getExtractorPluginForms(array &$form, FormStateInterface $form_state, array $default_settings = [], array $allowed_icon_pack = [], bool $wrap_details = FALSE): void { $icon_pack = $this->getDefinitions(); if (!empty($allowed_icon_pack)) { @@ -267,10 +267,8 @@ class IconPackManager extends DefaultPluginManager implements IconPackManagerInt // Create the container for each extractor settings used to have the // extractor form. $form[$icon_pack_id] = [ - '#type' => 'container', - // Name is used for js hide/show settings. - // @see web/modules/ui_icons/js/ui_icons.admin.js - '#attributes' => ['name' => 'icon-settings--' . $icon_pack_id], + '#type' => $wrap_details ? 'details' : 'container', + '#title' => $wrap_details ? $plugin['label'] : '', ]; // Create the extractor form and set settings so we can build with values. diff --git a/src/Plugin/IconPackManagerInterface.php b/src/Plugin/IconPackManagerInterface.php index 1781f2a80f5a0bbc8d81c146e1f9fb80ce33128c..2ed2138238568918e40f34ed04d764c1850111a8 100644 --- a/src/Plugin/IconPackManagerInterface.php +++ b/src/Plugin/IconPackManagerInterface.php @@ -78,8 +78,10 @@ interface IconPackManagerInterface extends PluginManagerInterface { * The settings for the forms (optional). * @param array $allowed_icon_pack * The list of icon set (optional). + * @param bool $wrap_details + * Wrap each form in details (optional). */ - public function getExtractorPluginForms(array &$form, FormStateInterface $form_state, array $default_settings = [], array $allowed_icon_pack = []): void; + public function getExtractorPluginForms(array &$form, FormStateInterface $form_state, array $default_settings = [], array $allowed_icon_pack = [], bool $wrap_details = FALSE): void; /** * Retrieve extractor default options. diff --git a/tests/src/Kernel/Plugin/IconPackManagerKernelTest.php b/tests/src/Kernel/Plugin/IconPackManagerKernelTest.php index 235d5786cf0baf232bf98c1915991a46dfefa320..903c901d586fe34c4aca2bb07c802994e5ef49da 100644 --- a/tests/src/Kernel/Plugin/IconPackManagerKernelTest.php +++ b/tests/src/Kernel/Plugin/IconPackManagerKernelTest.php @@ -169,12 +169,6 @@ class IconPackManagerKernelTest extends KernelTestBase { $expected = ['test_local_files', 'test_local_svg', 'test_local_svg_sprite', 'test_no_icons']; $this->assertSame($expected, array_keys($form)); - // Attributes is important, used by js for hidden/show. - $this->assertSame(['name' => 'icon-settings--test_local_files'], $form['test_local_files']['#attributes']); - $this->assertSame(['name' => 'icon-settings--test_local_svg'], $form['test_local_svg']['#attributes']); - $this->assertSame(['name' => 'icon-settings--test_local_svg_sprite'], $form['test_local_svg_sprite']['#attributes']); - $this->assertSame(['name' => 'icon-settings--test_no_icons'], $form['test_no_icons']['#attributes']); - // Check under settings form key. $this->assertArrayHasKey('width', $form['test_local_files']); $this->assertArrayHasKey('height', $form['test_local_files']); diff --git a/tests/src/Unit/IconExtractorSettingsFormTest.php b/tests/src/Unit/IconExtractorSettingsFormTest.php index 1c68b9bfd8a3ff3e10dfb609d3768b06c061a2cc..cb7b7da9fd5ef191f8f4d8b140a42f58d240aed4 100644 --- a/tests/src/Unit/IconExtractorSettingsFormTest.php +++ b/tests/src/Unit/IconExtractorSettingsFormTest.php @@ -36,7 +36,7 @@ class IconExtractorSettingsFormTest extends UnitTestCase { * @return array * The data for settings and expected. * - * @phpcs:disable + * @phpcs:disable */ public static function settingsFormDataProvider(): array { return [ @@ -63,7 +63,6 @@ class IconExtractorSettingsFormTest extends UnitTestCase { 'type' => 'string', 'size' => 22, 'maxlength' => 33, - 'required' => TRUE, 'placeholder' => 'My test string', 'pattern' => '_pattern_', 'prefix' => '_prefix_', @@ -78,7 +77,6 @@ class IconExtractorSettingsFormTest extends UnitTestCase { '#size' => 22, '#maxlength' => 33, '#pattern' => '_pattern_', - '#required' => TRUE, '#field_prefix' => '_prefix_', '#field_suffix' => '_suffix_', '#placeholder' => 'My test string',