diff --git a/core/lib/Drupal/Core/Form/FormHelper.php b/core/lib/Drupal/Core/Form/FormHelper.php index 5faa89b..878c118 100644 --- a/core/lib/Drupal/Core/Form/FormHelper.php +++ b/core/lib/Drupal/Core/Form/FormHelper.php @@ -10,7 +10,7 @@ use Drupal\Core\Render\Element; /** - * Encapsulates the caching of a form and its form state. + * Provides helpers to operate on forms. * * @ingroup form_api */ @@ -25,6 +25,8 @@ class FormHelper { * A partial or entire jQuery selector string to replace in #states. * @param string $replace * The string to replace all instances of $search with. + * + * @see drupal_process_states() */ public static function rewriteStatesSelector(array &$elements, $search, $replace) { if (!empty($elements['#states'])) { @@ -40,27 +42,27 @@ public static function rewriteStatesSelector(array &$elements, $search, $replace /** * Helper function for self::rewriteStatesSelector(). * - * @param array $ids - * States array element. - * @param $search + * @param array $conditions + * States conditions array. + * @param string $search * A partial or entire jQuery selector string to replace in #states. - * @param $replace + * @param string $replace * The string to replace all instances of $search with. */ - protected static function processStatesArray(array &$elements, $search, $replace) { - foreach ($elements as $id => $values) { + protected static function processStatesArray(array &$conditions, $search, $replace) { + // Retrieve the keys to make it easy to rename a key without changing the + // order of an array. + $keys = array_keys($conditions); + foreach ($conditions as $id => $values) { if (strpos($id, $search) !== FALSE) { $new_id = str_replace($search, $replace, $id); - if ($new_id != $id) { - // Replace the key and keep the array in the same order. - $keys = array_keys($elements); - $index = array_search($id, $keys, TRUE); - $keys[$index] = $new_id; - $elements = array_combine($keys, array_values($elements)); - } + // Replace the key and keep the array in the same order. + $index = array_search($id, $keys, TRUE); + $keys[$index] = $new_id; + $conditions = array_combine($keys, array_values($conditions)); } elseif (is_array($values)) { - static::processStatesArray($elements[$id], $search, $replace); + static::processStatesArray($conditions[$id], $search, $replace); } } } diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index cdf2e38..1816440 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -990,8 +990,16 @@ protected function buildExposedFiltersGroupForm(&$form, FormStateInterface $form $children = Element::children($row['value']); if (!empty($children)) { foreach ($children as $child) { - if (!empty($this->options['group_info']['group_items'][$item_id]['value'][$child])) { - $row['value'][$child]['#default_value'] = $this->options['group_info']['group_items'][$item_id]['value'][$child]; + foreach ($child['#states']['visible'] as $key => $state) { + if (isset($state[':input[name="options[operator]"]'])) { + $row['value'][$child]['#title'] = ''; + + if (!empty($this->options['group_info']['group_items'][$item_id]['value'][$child])) { + $row['value'][$child]['#default_value'] = $this->options['group_info']['group_items'][$item_id]['value'][$child]; + } + // Exit this loop and process the next child element. + break; + } } } } diff --git a/core/tests/Drupal/Tests/Core/Form/FormHelperTest.php b/core/tests/Drupal/Tests/Core/Form/FormHelperTest.php index fa9d5e4..cf127cd 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormHelperTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormHelperTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\system\Tests\Form\StatesTest. + * Contains \Drupal\system\Tests\Form\FormHelperTest. */ namespace Drupal\Tests\Core\Form;