Problem/Motivation

The 'Put the exposed form in a block' setting is not available on block displays, but it would be very useful with page manager and layout builder. It would provide much more control of the layout.

Proposed resolution

Currently \Drupal\views\Plugin\views\display\Block::usesExposedFormInBlock() returns $this->hasPath(). This can be changed to TRUE.

This will work well, because views always uses <current> route when view-URL/display-path is not available, for example: http://cgit.drupalcode.org/drupal/tree/core/modules/views/src/Form/Views...

Remaining tasks

+ write patch
- review

User interface changes

The "Exposed form in block" option will be available on block displays.

API changes

None.

Data model changes

None.

Comments

Leksat created an issue. See original summary.

leksat’s picture

Status: Active » Needs review
StatusFileSize
new443 bytes
leksat’s picture

Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ademarco’s picture

I queued this patch for testing against 8.1.x.

sonfd’s picture

Patch working for me.

claudiu.cristea’s picture

What happens if you try to place such a block using the core "Block layout" mechanism. Is the exposed block showing?

leksat’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
StatusFileSize
new789 bytes

#2 does not work with Drupal 8.1.3.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.

dan2k3k4’s picture

StatusFileSize
new628 bytes

Updated for 8.2.x and 8.3.x

dan2k3k4’s picture

StatusFileSize
new608 bytes

Updated for 8.2.x / 8.3.x

dan2k3k4’s picture

Status: Needs work » Needs review

- forgot to update status to needs review [my first 'patch' - Sorry for spamming you guys <3]

Status: Needs review » Needs work

The last submitted patch, 11: allow-2681947-11.patch, failed testing.

dan2k3k4’s picture

Version: 8.2.x-dev » 8.3.x-dev
dan2k3k4’s picture

Status: Needs work » Needs review
yogeshmpawar’s picture

StatusFileSize
new628 bytes

Rerolled the patch against 8.3.x because #11 failed to apply.

Status: Needs review » Needs work

The last submitted patch, 16: allow-2681947-16.patch, failed testing.

vasi1186’s picture

Status: Needs work » Needs review
StatusFileSize
new624 bytes

The #8 and #11 patches seem to be quite different. With #11, it is true it applies on 8.2, but it does not work, I cannot see the option anymore on the view edit form.

I attached a new patch.

Status: Needs review » Needs work

The last submitted patch, 18: allow-2681947-18.patch, failed testing.

vasi1186’s picture

Status: Needs work » Needs review
StatusFileSize
new634 bytes

This one should apply (at least for 8.2)

Status: Needs review » Needs work

The last submitted patch, 20: allow-2681947-20.patch, failed testing.

vasi1186’s picture

Status: Needs work » Needs review
StatusFileSize
new644 bytes

One more try.

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.

blazey’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #22 works flawlessly.

saltednut’s picture

Status: Reviewed & tested by the community » Needs work

Has anyone else tested this with an exposed form that has a 'Reset' button? This is what we are seeing when we try to Reset any exposed forms that are attached to a Views block.

Redirect, 404: /views/ajax?field_tags_target_id=downtown+%288%29&sort_by=created&sort_order=DESC&op=Reset

Edit: Some notes about reproducing...

The View Exposed Form setting 'Exposed form in block' needs to be set to "No" to replicate this. Using this patch, when 'Exposed form in block' is set to 'No' the exposed form still shows up and the form works, but it is attached to the top of the Views block. If the exposed form style is 'Basic' and "Include reset button (resets all applied exposed filters)" is checked, then the "Reset" button will show up.

The 'Reset' button will NOT show up at all if 'Exposed form in block' is set to 'Yes' -- this appears to be by design.

claudiu.cristea’s picture

Well. It needs tests, anyway. So, yes, "Needs work".

lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.44 KB
new3.08 KB

@brantwynn sounds like you are running into #2820347: Exposed filter reset redirects user to 404 page on AJAX view when placed as a block, which is unrelated to this feature.

Some basic tests for this, basically the page test now applied to a block display.

The last submitted patch, 27: 2681947-27-TEST_ONLY.patch, failed testing. View results

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.

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.

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.

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.

keszthelyi’s picture

StatusFileSize
new3.07 KB

Reroll for 8.7.x of #27

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

nickdickinsonwilde’s picture

Status: Needs review » Reviewed & tested by the community

Been using #33 for a year+ with no problems on D8.7 > 8.8 > 8.9. Using #33 on new Drupal 9.0>9.1 as well. Works seemlessly.

quietone’s picture

StatusFileSize
new3.07 KB

Re uploading the patch from #33 to make sure it tests with 9.2.x

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
@@ -193,12 +193,14 @@ public function testResetButton() {
   /**
    * Tests the exposed block functionality.
+   *
+   * @dataProvider providerTestExposedBlock
    */
-  public function testExposedBlock() {
+  public function testExposedBlock($display) {

This test is not clicking on any buttons. I think it is worth testing that.

I think we should test that the submit buttons work. So change the end of the this test to do something like:

    // Test that the correct option is selected after form submission.
    $this->assertCacheContext('url');
    $this->assertTrue($this->assertSession()->optionExists('Content: Type', 'All')->isSelected());
    foreach (['All', 'article', 'page'] as $argument) {
      $elements[0]->find('css', 'select')->selectOption($argument);
      $elements[0]->findButton('Apply')->click();
      $this->assertCacheContext('url');
      $this->assertTrue($this->assertSession()->optionExists('Content: Type', $argument)->isSelected());
      // @todo ensure content is as expected.
    }
    $elements[0]->findButton('Reset')->click();
    // @todo ensure content is as expected.
raman.b’s picture

Status: Needs work » Needs review
StatusFileSize
new5.3 KB
new2.79 KB

Addressing #39

handkerchief’s picture

pameeela’s picture

Title: Allow exposed-form-in-block for block displays » Allow "Put the exposed form in a block" setting to be used with views block displays
pameeela’s picture

Title: Allow "Put the exposed form in a block" setting to be used with views block displays » Allow 'Put the exposed form in a bloc'" setting to be used with views block displays
Issue summary: View changes
pameeela’s picture

Title: Allow 'Put the exposed form in a bloc'" setting to be used with views block displays » Allow 'Put the exposed form in a block' setting to be used with views block displays
abhijith s’s picture

StatusFileSize
new88.93 KB
new88.1 KB

Applied patch #40 and it works fine.The exposed form in a block option will be available for block displays after applying this patch.

Before patch:
before

After patch:
after

RTBC +1

mpotter’s picture

Status: Needs review » Reviewed & tested by the community

Since #39 was addressed, moving this back to RTBC. It works as designed for me also and fixes a major issue with using exposed filter blocks on non-ajax views.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 40: 2681947-40.patch, failed testing. View results

catch’s picture

Status: Needs work » Reviewed & tested by the community

Restoring status after HEAD was broken

  • catch committed 9f8f38d on 9.3.x
    Issue #2681947 by vasi1186, dan2k3k4, Leksat, Lendude, raman.b,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 9f8f38d and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

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

codebymikey’s picture

If the View has an alternative page display, it'll default to picking the first URL it can find (even if that view might be for a different purpose e.g. for a REST API).

References:
ViewsExposedForm::buildForm()
ViewExecutable::hasUrl()

Integration with "Link display" would be useful for controlling where the form submits to, or making use of ViewExecutable::$override_url.