From 128b22e3115d87a3b16379f6ce544757c67681ce Mon Sep 17 00:00:00 2001 From: Nedjo Rogers Date: Mon, 7 Dec 2020 17:50:33 -0800 Subject: [PATCH] GH-316: Cannot include two pattern select elements in same form --- src/Form/PatternDisplayFormTrait.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Form/PatternDisplayFormTrait.php b/src/Form/PatternDisplayFormTrait.php index 3d958421..6c3df8c8 100644 --- a/src/Form/PatternDisplayFormTrait.php +++ b/src/Form/PatternDisplayFormTrait.php @@ -2,6 +2,7 @@ namespace Drupal\ui_patterns\Form; +use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SortArray; use Drupal\ui_patterns\Plugin\PatternSourceBase; @@ -30,7 +31,7 @@ trait PatternDisplayFormTrait { * Default configuration coming form the host form. */ public function buildPatternDisplayForm(array &$form, $tag, array $context, array $configuration) { - + $pattern_select_id = Html::getUniqueId('patterns-select'); $form['pattern'] = [ '#type' => 'select', '#empty_value' => '_none', @@ -38,7 +39,7 @@ public function buildPatternDisplayForm(array &$form, $tag, array $context, arra '#options' => $this->patternsManager->getPatternsOptions(), '#default_value' => isset($configuration['pattern']) ? $configuration['pattern'] : NULL, '#required' => TRUE, - '#attributes' => ['id' => 'patterns-select'], + '#id' => $pattern_select_id, ]; $form['variants'] = ['#type' => 'container']; @@ -53,7 +54,7 @@ public function buildPatternDisplayForm(array &$form, $tag, array $context, arra '#weight' => 0, '#states' => [ 'visible' => [ - 'select[id="patterns-select"]' => ['value' => $pattern_id], + 'select[id="' . $pattern_select_id . '"]' => ['value' => $pattern_id], ], ], ]; @@ -63,7 +64,7 @@ public function buildPatternDisplayForm(array &$form, $tag, array $context, arra '#weight' => 1, '#states' => [ 'visible' => [ - 'select[id="patterns-select"]' => ['value' => $pattern_id], + 'select[id="' . $pattern_select_id . '"]' => ['value' => $pattern_id], ], ], 'settings' => $this->getMappingForm($pattern_id, $tag, $context, $configuration),