Problem/Motivation

When using a views exposed form as block. The block does not allow you to provide a title.

Proposed resolution

Patch provided

Remaining tasks

  • Add test coverage for the bug
  • Write the upgrade path Reviewed in #61, and re-factored in #66
  • Manually test for the upgrade path #57
  • Update the change record (see #52)
  • Write upgrade path tests #68

User interface changes

None

API changes

None

Data model changes

None

Original Summary

I have created a simple Views page with several exposed filters with Views option: Exposed form in block: Yes.
The block is configured to "Display title" in block config settings.
When the block is configured to display in a region, the Label/title is not displaying.
I have dumped the block variables out with template_preprocess_block() and label key is empty ('label' => string(0) "").
The result is the same when the block is configured to override title.
Is this a bug or have I missed something?

CommentFileSizeAuthor
#72 2720101-72.patch7.66 KBManuel Garcia
#72 interdiff-2720101-68-72.txt915 bytesManuel Garcia
#71 after-Fiery_chili_sauce___Umami_Food_Magazine.png40.82 KBjoelpittet
#71 Before-Fiery_chili_sauce___Umami_Food_Magazine.png138.08 KBjoelpittet
#71 Configure_block___Umami_Food_Magazine.png65.78 KBjoelpittet
#68 2720101-68.patch7.72 KBManuel Garcia
#68 interdiff-2720101-66-68.txt4.11 KBManuel Garcia
#66 2720101-65.patch4.37 KBManuel Garcia
#66 interdiff-2720101-53-65.txt2.09 KBManuel Garcia
#53 2720101-53.patch4.63 KBManuel Garcia
#53 interdiff-2720101-43-53.txt1.18 KBManuel Garcia
#43 2720101-43.patch3.46 KBManuel Garcia
#43 interdiff-41-43.txt1.58 KBManuel Garcia
#41 2720101-41.patch3.34 KBManuel Garcia
#41 interdiff-38-41.txt795 bytesManuel Garcia
#38 interdiff-2720101-30-38.txt2.91 KBJacobSanford
#38 2720101-38.patch3.28 KBJacobSanford
#30 2720101-30.patch3.26 KBManuel Garcia
#30 interdiff.txt1.01 KBManuel Garcia
#28 2720101-28.patch2.25 KBjofitz
#24 2720101-24-views-exposed-block-title-test.diff2.21 KBcamilocodes
#7 2720101-7-views-exposed-block-title.diff3.23 KBdobe
#7 2720101-7-views-exposed-block-title-test.diff2.21 KBdobe
#4 2720101-4-views-exposed-block-title.diff1.01 KBdobe
#3 2720101-3-views-exposed-block-title.diff1.01 KBdobe
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davewilly created an issue. See original summary.

dobe’s picture

Assigned: Unassigned » dobe
Issue tags: +neworleans2016

I can confirm this issue does exist. I am going to try an fix.

dobe’s picture

Component: block.module » views.module
Status: Active » Needs review
FileSize
1.01 KB

Ok so I found the issue. The title is not being set lol... Here is a patch.

dobe’s picture

Version: 8.1.1 » 8.2.x-dev
Assigned: dobe » Unassigned
Issue summary: View changes
FileSize
1.01 KB

This issue applies to 8.x-2.x as well. The attached patch fixes it.

**Update** apologize didn't realize you can run patch against multiple versions. #3 and #4 should be the exact same.

dobe’s picture

Issue summary: View changes
dawehner’s picture

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

This totally makes sense in general! Some kind of tests for that would be nice though.

dobe’s picture

dobe’s picture

Status: Needs work » Needs review
dobe’s picture

The last submitted patch, 7: 2720101-7-views-exposed-block-title-test.diff, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2720101-7-views-exposed-block-title.diff, failed testing.

The last submitted patch, 7: 2720101-7-views-exposed-block-title-test.diff, failed testing.

dobe’s picture

Status: Needs work » Needs review
dobe’s picture

Patch in #7 passed after migration build issues were fixed today.

dobe’s picture

Issue tags: -Needs tests

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Archual’s picture

Thanks! It is works.

davewilly’s picture

Works for me also. Thanks.

BenR’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! it works.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php
@@ -32,6 +33,14 @@ public function build() {
+        '#allowed_tags' => Xss::getHtmlTagList()

Given this is an important security consideration I think this should have test coverage - both that certain html tags like strong are permitted but also that others like script are stripped.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ac’s picture

Status: Needs work » Reviewed & tested by the community

This needs to be committed ASAP please. It works correctly and without it there is a lot of confusion.

camilocodes’s picture

Status: Reviewed & tested by the community » Needs review

Composer seems unable to apply this patch for 8.3. Any ideas?

camilocodes’s picture

Re-rolled for 8.4.x
This is my first contribution ever, so I hope I have proceeded correctly and welcome any pointers.

Status: Needs review » Needs work

The last submitted patch, 24: 2720101-24-views-exposed-block-title-test.diff, failed testing.

camilocodes’s picture

It seems unlikely but apparently the patch has stopped working altogether in 8.3. I re-rolled it for 8.4 and composer patches it correctly, but my exposed filter title, which was displaying in 8.2 using the patch from comment #7, is nowhere to be found.

ac’s picture

There are two patches in #7 - one is a bugfix for the issue and one is adding a test. The bugfix applies cleanly to 8.3.*, the test does not.

jofitz’s picture

Status: Needs work » Needs review
FileSize
2.25 KB

Patch in #24 no longer applies. Re-rolled.

Status: Needs review » Needs work

The last submitted patch, 28: 2720101-28.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
1.01 KB
3.26 KB

It looks like the previews reroll on #24 was missing the changes to core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php - adding that back now on top of #28.

Manuel Garcia’s picture

@alexpott Re #20, Xss::getHtmlTagList() will just allow ['a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd'], and using that with #allowed_tags means that this will be handled by Renderer::ensureMarkupIsSafe(), which is already tested on RendererTest::providerTestRenderBasic() so don't think we should be explicitly testing the usage of #allowed_tags here.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I agree with #31, extra testcoverage for the xss coverage seems to be overkill. While this might seem like trusting the implicit testcoverage, I feel that it's not the responsability of everything that uses '#allowed_tags' to also write explicit testcoverage.

This has specific testcoverage and does work, so marking as RTBC.

larowlan’s picture

+++ b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php
@@ -46,6 +47,14 @@ public function build() {
+    // Set the blocks title.

nit either block or block's - we are talking about one block here - can be fixed on commit

Berdir’s picture

I noticed this as well and was about to create a new issue for it but luckily found this.

What I was wondering is the impact this will have on existing sites. It is a bugfix but it has a visual effect on existing sites that are using such a block with the default configuration which is configured to show titles.

It's quite likely that sites either didn't want a title and are happy with the current output or they did some sort of workaround like a custom block template to get one. And if they update, they might end up with an unexpected new title or even a duplicate title now, depending on what they did.

Considering that, we might want to at least do a change record to notify people about this change/fix and if we want to be extra strict, we could consider to disable the show title checkbox on existing blocks to basically keep the same behavior as we have now?

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

For #35

I agree, we should default to no title for existing blocks with instructions in change record

jbitdrop’s picture

Agree on @Berdir and @larowlan. And on @alexpott: what about the security concerns he stated @ #20 ? I didn't saw any further mentioning.

JacobSanford’s picture

@Manuel Garcia's patch in #30 no longer applied to 8.5.x. A reroll with no further modifications is attached.

dawehner’s picture

+++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
@@ -199,7 +199,30 @@ public function testExposedBlock() {
+    $this->assertText($view->getTitle(), 'Block title found.');
...
+    $this->assertText('Custom title', 'Custom block title found.');

Should we also test that the original views title is not displayed? If you think about it, it could easily still be the case that the views title is rendered somehow.

jbitdrop’s picture

@dawehner: true.

Manuel Garcia’s picture

Addressing #39

alexpott’s picture

Status: Needs review » Needs work

Re #20 given that we expect to be able to handle markup in the label I think we should test this. It's not testing #markup and its abilities, it is asserting on our expectations.

+++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
@@ -199,7 +199,31 @@ public function testExposedBlock() {
+    $block->getPlugin()->setConfigurationValue('views_label', 'Custom title');

Let's out some html in here that will be filtered and some that won't.

Also #35 still needs to be addressed.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
1.58 KB
3.46 KB

OK I think I know what you mean @alexpott, thanks for the kind explanation. Attempting to address #20/#42 here :)

Stil to do #35.

alexpott’s picture

@Manuel Garcia yep that's exactly what I meant. Thanks.

Manuel Garcia’s picture

So by the sounds of it, #35 and #36, it seems that we need an upgrade path to set the label_display configuration for all existing exposed filter blocks to FALSE, right? So that means we'd also need upgrade path tests...

I'm not sure what's best to be honest, if we go the upgrade path way, people will need to not revert their configuration before updating their exports, or they could see the new titles showing up.

So although admitedly less so, that's stil risky, its just one less step if I'm not mistaken, assuming all they want to do is disable the new funcionality.

I suppose what I am trying to say is that website devs will need to take action in any case, even if its just to make use (or not) of this functionality and/or remove their template workarounds.

Manuel Garcia’s picture

Added a CR for this, tried to be as clear as possible, but it could definetly use a review https://www.drupal.org/node/2925510

Berdir’s picture

> I'm not sure what's best to be honest, if we go the upgrade path way, people will need to not revert their configuration before updating their exports, or they could see the new titles showing up.

That's always the case for all updates. updates can change configuration. In most cases that is reproducible, you run updates locally/on test, then export config, then deploy and updates then make the change and then you don't have to import it (exceptions are updates that generate config/random-ish values, those are a problem)

The bigger problem is that block config entities isn't the only thing that use block config entities. Writing an update function for that isn't going to help those that placed this block with page_manager/panels.

Manuel Garcia’s picture

Right @Berdir, makes sense.

The bigger problem is that block config entities isn't the only thing that use block config entities. Writing an update function for that isn't going to help those that placed this block with page_manager/panels.

So then, how to procede from here? Is the CR enough or do we need an upgrade path?
If we need an upgrade path, what should it look like?

imanoop’s picture

Thank you, actually title code was missing.
After this patch now title is appearing on my Views Exposed Form Block.

Thanks.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

frankdesign’s picture

Patch at #43 works perfectly. Exactly what I needed

Thanks

F

Manuel Garcia’s picture

Status: Needs review » Needs work
Issue tags: +Needs upgrade path, +Needs upgrade path tests

OK, If I understood the situation correctly, I believe that the upgrade path should update existing views, setting label_display to FALSE. This is to keep these blocks working as before. See #35 and #36.

Once that is done, we will need to update the CR to reflect this change:

The update path updated existing views disabling the label_display setting, so as preserve expected previous functionality. If you'd like to make use of this setting now, please make sure you were not already manually printing this on your templates so as to avoid displaying the block titles twice.

We should also include in the CR a mention of other modules that may be inserting this blocks on the site, like page_manager/panels, because the update path cannot cover for this, something like:

If your site is using other means of inserting these blocks into the page, like page_manager/panels, make sure to revisit this setting so as to prevent presenting the titles twice.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
1.18 KB
4.63 KB

Here is a start on the upgrade path.

Cauliflower’s picture

Tested and works as expected.

fonant’s picture

Tested and works as expected here.

Manuel Garcia’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs upgrade path

Thanks @Cauliflower & @fonant for reporting on this.

Still to do here as far as I can see:

  • Test for the upgrade path
  • Update the CR (see #52)
joelpittet’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs upgrade path tests

Tested the upgrade path:

  1. Applied the patch
  2. rebuilt cache
  3. looked for title, shows up
  4. run database update and is hidden
  5. Enable it again (yay)
joelpittet’s picture

Issue tags: +DrupalWTF
raajkumar.kuru’s picture

Can any one please how can i apply patches using composer

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
+++ b/core/modules/views/views.install
@@ -508,3 +508,26 @@ function views_update_8500() {
+/**
+ * Update exposed filter blocks label display to be disabled.
+ */
+function views_update_8600() {
+  /** @var \Drupal\block\BlockInterface $block_storage */
+  $block_storage = \Drupal::entityManager()->getStorage('block');
+  $config_factory = \Drupal::configFactory();
+
+  foreach ($config_factory->listAll('views.view.') as $view_config_name) {
+    $view = $config_factory->get($view_config_name);
+    foreach ($view->get('display') as $display_id => $display) {
+      if (isset($display['display_options']['exposed_block']) && $display['display_options']['exposed_block'] == 1) {
+        $plugin_id = 'views_exposed_filter_block:' . $view->get('id') . '-' . $display_id;
+        $blocks = $block_storage->loadByProperties(['plugin' => $plugin_id]);
+        foreach ($blocks as $block) {
+          $block->getPlugin()->setConfigurationValue('label_display', FALSE);
+          $block->save();
+        }
+      }
+    }
+  }
+}

This should be a post update function as we're using the full entity API to save the blocks and probably should be batched in some way since some sites can have a lot of blocks.

Also we need an update test.

Manuel Garcia’s picture

Thanks for the reviews!

I think this is the tag you meant @alexpott :)

Manuel Garcia’s picture

Issue summary: View changes

Updating the Remaining tasks section of the issue summary.

Manuel Garcia’s picture

Issue summary: View changes
alexpott’s picture

FYI for updating config entities we have \Drupal\Core\Config\Entity\ConfigEntityUpdater() that helps with the batching.

Manuel Garcia’s picture

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

Thanks @alexpott it sure does help :)
Addressing #61 here, we still need an upgrade path test.

Manuel Garcia’s picture

+++ b/core/modules/views/views.post_update.php
@@ -366,3 +366,18 @@ function views_post_update_table_display_cache_max_age(&$sandbox = NULL) {
\ No newline at end of file

Oops /shrug

Manuel Garcia’s picture

Here is an upgrade path test

Manuel Garcia’s picture

Issue summary: View changes
frankdesign’s picture

Just tested patch #53 on Drupal 8.6.1 and works as expected.

Thanks a mil

F

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
65.78 KB
138.08 KB
40.82 KB

Tested this out:

  1. Currently no block titles are shown for exposed filter blocks.
  2. After the patch applied,
  3. The update hook updates preserves that state and ensures the titles continue to be as they where which is great so we don't have complaints of exposed titles show up after updates, and it preserves my overwritten title even thought it's now displayed unchecked now the updb ran.
  4. I check to show the title again and now it shows!

Configuration:

Before:

After:

Also did a scan through the code. A couple of minor nitpiks:

  1. +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
    @@ -199,7 +199,31 @@ public function testExposedBlock() {
    +    $block->getPlugin()->setConfigurationValue('label_display', FALSE);
    
    +++ b/core/modules/views/views.post_update.php
    @@ -366,3 +366,18 @@ function views_post_update_table_display_cache_max_age(&$sandbox = NULL) {
    +      $block->getPlugin()->setConfigurationValue('label_display', '0');
    

    Should it be '0' or FALSE?

  2. +++ b/core/modules/views/tests/src/Functional/Update/ExposedFilterBlocksUpdateTest.php
    --- a/core/modules/views/views.post_update.php
    +++ b/core/modules/views/views.post_update.php
    
    +++ b/core/modules/views/views.post_update.php
    @@ -366,3 +366,18 @@ function views_post_update_table_display_cache_max_age(&$sandbox = NULL) {
    \ No newline at end of file
    

    Needs another linebreak

  3. +++ b/core/modules/views/views.post_update.php
    @@ -366,3 +366,18 @@ function views_post_update_table_display_cache_max_age(&$sandbox = NULL) {
    +    if (substr($block->getPluginId(), 0, strlen('views_exposed_filter_block:')) === 'views_exposed_filter_block:') {
    

    Can be just strpos() === 0?

Manuel Garcia’s picture

Thanks @joelpittet !

Re #71.1 Unfortunately that is defined in the schema as a string, so its either that or it will fail (see core/config/schema/core.data_types.schema.yml line 309).

Fixed the #71.2 and #71.3 nitpicks here.

Manuel Garcia’s picture

Issue summary: View changes
nicholasThompson’s picture

Thanks - this has resolved my missing title on an exposed views filter block! I thought I was going mad ;)

Applied cleanly to 8.6.1

frankdesign’s picture

Patch at #72 applied perfectly to Drupal 8.6.2

Please commit :o)

F

ksi’s picture

Since 8.1 and for some years this error is present in every version. And after finding and applying a (version specific) patch the title is (was) displayed.

I don't understand why this bug can't be fixed in all versions and for the future. Why is there a need to detect, report, check, fix (or search for a patch) and finally patch everywhere the same bug from version to version?

  • catch committed 099d3e6 on 8.7.x
    Issue #2720101 by Manuel Garcia, dobe, JacobSanford, camilocodes, Jo...
catch’s picture

Status: Reviewed & tested by the community » Fixed

@ksi issues have to get to RTBC, reviewed by a core committer, then committed in order to make it into a release. There are hundreds of issues in the queue, and while some are fixed within days, some take several years to get resolved - this could be down to any number of factors depending on the issue. This one's done though now and will be in 8.7.0 when it comes out. I didn't commit to 8.6.x due to the configuration update.

Committed ff031bb and pushed to 8.7.x. Thanks!

Manuel Garcia’s picture

Issue summary: View changes

Thanks for committing catch!

I have updated the CR with regards to #52, fixed the branch & version for it and published it.

Status: Fixed » Closed (fixed)

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

nofue’s picture

It seems labels in views blocks are still missing from 8.8.4 …

quietone credited Chi.

quietone credited Lendude.

quietone credited xjm.

quietone’s picture

Closed #2629566: Label is not shown for blocks with exposed forms as a duplicate. Adding credit for the work done over there.