Problem/Motivation

\Drupal\views\Plugin\views\filter\NumericFilter does not set a label or description for the 'minimum' filter element if the filter is exposed and using the 'between' filter.

Before

After #3

Proposed resolution

Display the exposed filter label as Views did in Drupal 7.

Remaining tasks

None.

User interface changes

Add the label like it was used in Drupal 7.

API changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because form elements miss titles (accessibility)
Issue priority Minor because the bug is a regression, but does not break behavior or destroy data.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Status: Active » Needs review
FileSize
734 bytes
andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
aerozeppelin’s picture

Status: Needs work » Needs review
FileSize
1.37 KB
2.09 KB

Added tests as mentioned in #2.

Lendude’s picture

Title: Missing label for exposed numeric filter » Missing label for exposed numeric filter when using 'between' filter
Issue summary: View changes
Issue tags: -Needs tests +VDC
FileSize
10.5 KB
11.69 KB

Looks good. Manually tested it, added screenshots.

Lendude’s picture

+++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php
@@ -199,7 +199,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) {
+        '#title' => !$exposed ? $this->t('Min') : $this->exposedInfo()['label'],

Should we add 'between' after this or just leave it to the site builder to do so. Adding between would leave you with a sensible default when people don't change the label. And since you are stuck with 'And' as the label for the max field so adding more hardcoded labels might not be that bad. Just a thought...

Lendude’s picture

Title: Missing label for exposed numeric filter when using 'between' filter » Missing label and description for exposed numeric filter when using 'between' filter
Issue summary: View changes
FileSize
1.66 KB
2.42 KB

Might as well fix that the description is not shown either when using the 'between' filter. Fix and test for that. Bit of a scope creep, but fits in so nicely with the other fix.

dawehner’s picture

+++ b/core/modules/views_ui/src/Tests/FilterNumericWebTest.php
@@ -92,6 +92,30 @@ public function testFilterNumericUI() {
+    $this->assertText('And');
+    $this->assertText('Age between');
+    $this->assertText('Paul');
+    $this->assertText('Ringo');
+    $this->assertText('George');
+    $this->assertNoText('Meredith');
+    $this->assertNoText('John');
+    // Test if the description is shown.

It seems to be that we should not just the existence of the strings on the page but better also some css selectors. In general this test is about the exposed filter labels, so I don't get why we need to check for the actual view result using Paul, Ringe, George etc.

Lendude’s picture

@dawehner so maybe something like this?

Seems like the Beatles names test are there to check the proper working of the filter, those asserts are also done for the other filter settings in the same test. But since there is test coverage for the proper working of the filter in Drupal\views\Tests\Handler\FilterNumericTest that seems redundant.

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/views_ui/src/Tests/FilterNumericWebTest.php
@@ -92,6 +92,26 @@ public function testFilterNumericUI() {
+    $this->assertRaw("<div id=\"edit-age-min--description\" class=\"description\">\n      Description of the exposed filter\n    </div>", 'Between filter description found');

IMHO we should really use cssSelect() instead. The test should not bind everything to the rendered HTML.

Lendude’s picture

Status: Needs work » Needs review
FileSize
996 bytes
2.5 KB

Changes per #9 to check for css selector and not the whole HTML with all the spaces and stuff.

dawehner’s picture

+++ b/core/modules/views_ui/src/Tests/FilterNumericWebTest.php
@@ -110,8 +110,9 @@ public function testFilterNumericUI() {
+    $this->assertEqual(count($this->cssSelect('.form-item-age-min .description')), 1);
+    $this->assertText('Description of the exposed filter');

Why do you not look into the result of cssSelect? The description is in there ...

Lendude’s picture

Yeah the description is there but still with all the extra whitespace characters, so needed to trim() it to make it ok (and not add all the whitespace crap to the test).

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for doing that though!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 63c3cac and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed 5ea2d13 on 8.1.x
    Issue #2480719 by Lendude, aerozeppelin, Xano, dawehner: Missing label...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.