Problem/Motivation

"More link" on view's block display does not take display arguments into account.

Steps to reproduce

  1. Create a view with a page and a block
  2. Add exposed filter(s) to both
  3. Configure "more link" to point to the page display (not a custom URL)

Proposed resolution

  1. Fix the `getMoreurl()` method of the view

Value from the block's exposed filter should be passed as an argument to the page.

E.g. for /search page path the link should contain /search?search=[search_query] in its path.

Remaining tasks

- Needs review of sub-system maintainer.
- Fix the failing test. See if those are unrelated

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Original report by @d.novikov

Steps to reproduce:

  1. Create a view with a page and a block
  2. Add exposed filter(s) to both
  3. Configure "more link" to point to the page display (not a custom URL)

Expected behavior:
Value from the block's exposed filter should be passed as an argument to the page.

E.g. for /search page path the link should contain /search?search=[search_query] in its path.

Instead, the link contains /search part only, either for cached and not cached views.

Issue fork drupal-3105643

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

d.novikov created an issue. See original summary.

d.novikov’s picture

Suggested patch returns back logic from 8.7.x:

public function renderMoreLink() {
[...]
    // If the user has supplied a custom "More" link path, replace any
    // argument tokens and use that for the URL.
    if ($this
      ->getOption('link_display') == 'custom_url' && ($override_path = $this
      ->getOption('link_url'))) {
[...]
}

Status: Needs review » Needs work
d.novikov’s picture

StatusFileSize
new2.67 KB

Updated the patch.

d.novikov’s picture

Status: Needs work » Needs review

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Version: 9.4.x-dev » 10.1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Bug Smash Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.

This appears like it could still be relevant (code still seems to be the same but didn't test issue)

This will need a valid test to verify the bug and that it's fixed.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new11.05 KB
new13.72 KB
new11.05 KB

- Added the test cases and test-only patch to reproduce the issue.
- Test case is passing on local with the patch.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the test!

Testing the code using the view from the patch

On Drupal 10.1.x with a standard install
Place the view block in the content reason
Create a few pieces of content of articles and basic pages
While on one of the pages I filter for articles.
Click "More" links and it takes me to the view page
Confirmed the parameter is based also.

Confirmed without the fix following the same steps the parameter is not based.

mohit_aghera’s picture

Looks like "test-only" patch is triggered by the bot for re-tests.
Not sure what is the right approach to let test bot know about picking up correct patch.
Updating weight of the patch to see how it goes.

mohit_aghera’s picture

StatusFileSize
new13.72 KB

Re-uploading the same patch again as bot is testing test-only patch.

xjm’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new105.85 KB
new117.86 KB
  1. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2137,33 +2137,34 @@ protected function getMoreUrl() {
         // Return the display URL if there is no custom url.
         if ($this->getOption('link_display') !== 'custom_url' || empty($path)) {
    

    I think the inline comment here needs to be updated, because we are no longer returning early.

  2. +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2137,33 +2137,34 @@ protected function getMoreUrl() {
    +    else {
    +      $parts = UrlHelper::parse($path);
    

    The "else" also probably needs an inline comment now too, starting with "Otherwise..." and describing what it is doing.
     

  3. I checked and the only code that happens after the new "else" closes is:

        // Merge the exposed query parameters.                                      
        if (!empty($this->view->exposed_raw_input)) {
          $url->mergeOptions(['query' => $this->view->exposed_raw_input]);
        }
        return $url;
    

    I was trying to figure out if that should apply to both the cases in this if, and if we needed test coverage for both of them:

    +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
    @@ -2137,33 +2137,34 @@ protected function getMoreUrl() {
         if ($this->getOption('link_display') !== 'custom_url' || empty($path)) {
    

    I could not figure out what custom_url meant from the code, so I installed core and poked around the Views UI, under the "More" link settings, under the pager settings, under the display path settings... still for the life of me could not find it. This was my best clue:

          case 'link_display':
            $form['#title'] .= $this->t('Which display to use for path');           
            $options = [FALSE => $this->t('None'), 'custom_url' => $this->t('Custom URL')];
    

    This is what the UI says about it:
     'This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' section under pager. You can override the URL at the link display setting.'

    ...But I still could not find a "link display" section under "pager", or a "link display setting".

    I grepped and found a view where that setting was used:

    core/modules/user/config/optional/views.view.user_admin_people.yml:      link_display: page_1
    

    Poked around that view in the UI. Still can't find it. From the structure of the yaml, I expect it to be a top-level setting of the view, toward the end. All the references I could find to it in tests seemed to set the option manually, rather than via the form. I finally found this line in the functional (non-JS) display tests:
    $link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display';

    So in desperation I disabled JavaScript and navigated to http://127.0.0.1:8888/admin/structure/views/nojs/display/user_admin_people/page_1/link_display

    Which is this:
    Form showing 'Which display to use for path' form with three radio options

    Okay, so that looks like the right thing. Except after I submit that form, there seems to be no way to get back to it... indeed, link_display does not appear anywhere in the page source for the view with JS off.

    Re-reading the help text, I saw that it said something about being used if there was more than one page display. Except admin/people only has one page display, so why would it be set then? I tried adding a second page display... still could not figure out how to get to that form from the main views UI.

    So how on earth does this get configured by the user? Is it dead code? An orphaned setting? It's been awhile, and I worked on the Views in Drupal Core initiative full-time, and I'm nominally still listed as a maintainer, but I cannot tell after the better part of an hour where this option is configured. Can anyone help?

    So, needs tests... maybe? And needs followup... maybe?

xjm’s picture

Issue summary: View changes
Issue tags: +Needs followup
StatusFileSize
new25.71 KB

Aha, I finally found it! It's a setting that only applies to block displays. As per the STR in the IS and the whole point of the issue. I get this option if I add a block display to admin/people:
 page'

So we definitely need a followup to conditionally display the "More link" section only on block displays, because it's confusing as heck on page displays. Also why is the form accessible with JS off for page displays?

Edit: The other question is, why is this set on the user view and other views where there is no block display, only a page display?

xjm’s picture

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

Based on all that, I think we need test coverage for both cases. Edit: When a custom URL is set but the path is empty (?).

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

johnv’s picture

Component: views.module » views_ui.module

mohit_aghera’s picture

Hi @xjm
I've fixed the following issues from comment #19

  • Point 1
  • Point 2

Comment is updated for both the cases.

Regarding point 3:
- I've added the new test that validates both the points.
Fixed few more things in the MR

About the custom_url option:
- Primarily it is visible on the block plugin display and other non-page display.
So I believe we should hide it from the page display?

Probably we can use the inputs from the sub-system maintainer.
This might cause confusion to people as `More` link on the page display might not make sense.

I notice that there is no option to configure the link, it just allows to enable/disable link.
Which is correct if we want to keep option.

I'm happy to walk you through the views setup, feel free to ping me in #bugsmash.

Regarding #20
I agree with you for this one.
We can disable it from the page display and keep it active for block display.

Hiding the patches since we have a MR now.
Keeping issue in needs works since there are a few unrelated test failures that I'm looking into it.

mohit_aghera’s picture

Issue summary: View changes
mohit_aghera’s picture

Issue summary: View changes

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.