\Drupal\views_ui\ViewListBuilder::render() builds a render array for the ViewListBuilder.

The local variable used to hold this render array is named $list

But there is one element, and only one element, that is put into the $form array. The $form variable is not defined or used anywhere else, so this is dead, non-functioning code. Here's an excerpt:

    $list['#type'] = 'container';
    $list['#attributes']['id'] = 'views-entity-list';

    $list['#attached']['library'][] = 'core/drupal.ajax';
    $list['#attached']['library'][] = 'views_ui/views_ui.listing';

    $form['filters'] = [                    // <--- Uses $form instead of $list
      '#type' => 'container',
      '#attributes' => [
        'class' => ['table-filter', 'js-show'],
      ],
    ];

    $list['filters']['text'] = [
      '#type' => 'search',
      '#title' => $this->t('Filter'),
      '#title_display' => 'invisible',

Putting the search form element into a container was a change was made a long time ago in #2087327-20: [Regression from D7] Add text search functionality to views listing page. Apparently no-one ever noticed that patch didn't do what it was supposed to do, as a result of using $form instead of $list.

The attached patch fixes that mistake by changing $form to $list, and consequently adds the functionality originally intended by #2087327-20: [Regression from D7] Add text search functionality to views listing page.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR created an issue. See original summary.

TR’s picture

Status: Active » Needs review
TR’s picture

Issue tags: +Novice
pratik.mehta19’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, views-list-builder.patch, failed testing. View results

angel.h’s picture

I think that changing the code like this is not a good idea. This might cause a regression given the fact that this code has been like this from
8.0.x-dev. I think the safest thing would be to just remove the variable.

angel.h’s picture

Issue tags: +Needs tests

I also think we need tests to check that the initial functionality did not change.

TR’s picture

Status: Needs work » Needs review
Issue tags: +JavaScript

Markup before the patch:

<div class="js-form-item form-item js-form-type-search form-type-search js-form-item- form-item- form-no-label">
  <label class="visually-hidden">Filter</label>
  <input class="views-filter-text form-search" data-table=".views-listing-table" autocomplete="off" title="Enter a part of the view name, machine name, description, or display path to filter by." type="search" size="60" maxlength="128" placeholder="Filter by view name, machine name, description, or display path" />
</div>

Markup after the patch:

<div class="table-filter js-show">
  <div class="js-form-item form-item js-form-type-search form-type-search js-form-item- form-item- form-no-label">
    <label class="visually-hidden">Filter</label>
    <input class="views-filter-text form-search" data-table=".views-listing-table" autocomplete="off" title="Enter a part of the view name, machine name, description, or display path to filter by." type="search" size="60" maxlength="128" placeholder="Filter by view name, machine name, description, or display path" />
  </div>
</div>

That's it. One stand-alone form element wrapped in an extra div. Nothing removed.

The JavaScript attached to that form element continues to work because the existing classes haven't been removed so the selectors all remain valid. @dawehner confirmed this in #2087327-21: [Regression from D7] Add text search functionality to views listing page.

This form element exists only for use by the JavaScript; it is not involved in the form validation or submission. Nothing else on the page is or can be affected by this change and there's nothing additional to test that isn't already tested on that page. Unless you REALLY think we should test to ensure the js-show class shows up on that page, which isn't something we do ANYWHERE else in core.

The purpose of adding this new div is stated by @tstoeckler in #2087327-20: [Regression from D7] Add text search functionality to views listing page:

Unlike all other JS-filter-thingies in core (modules page, simpletest test page) this one is not hidden if there's no JS, even though it doesn't do anything when JS is disabled. This patch simply copies how the existing two forms do it behavior straight into ViewListController.

Those two other pages he mentions both use exactly the structure restored in this patch:
@see \Drupal\system\Form\ModulesListForm
@see \Drupal\simpletest\Form\SimpletestTestForm

@tstoeckler, @dawehner, and @webchick all approved of this change in #2087327: [Regression from D7] Add text search functionality to views listing page.

I really don't think we need to re-litigate this.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kimberlydb’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
179.88 KB
192.33 KB

Verified this is the minor markup change and filtering still works as expected.

Before & after screenshots attached.

alexpott’s picture

Title: Dead code in ViewListBuilder » Fix hiding view filter on admin/structure/views when JS disabled
alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

I think changing this markup is okay - it is ViewsUI markup and therefore not markup for the normal use case and it is only for the javascript filter on the page. It also fixes the page for the non-js usecase so I'm not taking #6 into account. I thought about #7 and requiring tests but I'm not sure that testing this is really that important and I'm also not how to test the functionality without asserting against the markup which doesn't feel that valid.

But also because this is a markup change and only a minor bugfix I'm going to commit only to 8.8.x and give anyone who is relying on the current markup sometime to change their code to support this as well. I do feel this is exceptionally unlikely but with Drupal that someone relies of something extremely edge proves to be the norm so no harm in being cautious.

Committed f7aeba5 and pushed to 8.8.x. Thanks!

  • alexpott committed f7aeba5 on 8.8.x
    Issue #3033979 by TR, kimberlydb: Fix hiding view filter on admin/...

Status: Fixed » Closed (fixed)

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