Skip to content
Snippets Groups Projects
Commit fd336ef0 authored by Jean Valverde's avatar Jean Valverde :construction_site:
Browse files

Merge branch '3469119-1.0.0-alpha3-field-formatter' into '1.0.x'

Issue #3469119 by mogtofu33: Field formatter details, no required in settings

See merge request !10
parents f8ce490f 78ed8973
No related branches found
No related tags found
No related merge requests found
Pipeline #259045 passed
......@@ -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
......
......@@ -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.
......
......@@ -94,7 +94,6 @@ class IconExtractorSettingsForm {
'size' => '#size',
'maxlength' => '#maxlength',
'pattern' => '#pattern',
'required' => '#required',
'prefix' => '#field_prefix',
'suffix' => '#field_suffix',
'placeholder' => '#placeholder',
......
......@@ -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.
......
......@@ -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.
......
......@@ -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']);
......
......@@ -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',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment