Problem/Motivation

When using the "Alternating view mode"-option in the Display Suite row plugin, it is possible to trigger incorrect view modes on items.

Our scenario:
- Fixed number of elements on the homepage
- Element 1 has view mode V1, elements 2-3-4 have view mode V2
- No pager

Occassionally, we would see all 4 elements in view mode V1. Clearing the cache always resolved this issue. After debugging, we tracked this down to legacy URL's hitting the site. The previous iteration of the site did contain a pager on the homepage. Whenever a legacy URL containing "?page=1" hit the site, the current display suite logic (taking the page number straight from the URL) assumed that we were no longer on the first page (even though views was still showing the first 4 elements, and there is no pager/multiple pages).

Proposed resolution

Instead of taking the page number straight from the URL/request/query parameters, extract the current page number via the Views pager object.

Remaining tasks

Review and commit patch.

User interface changes

None.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr.baileys created an issue. See original summary.

borisson_’s picture

Issue summary: View changes

This looks like a really simple patch, great detective work there @mr.baileys. I've queued the testbots, when they come back green I think this can move to RTBC.

Status: Needs review » Needs work

The last submitted patch, ds-view-alternating-view-modes-page.patch, failed testing. View results

borisson_’s picture

Status: Needs work » Needs review

The tests don't seem to break on the latest commit, but this looks like it broke the tests quite hard.

\Drupal\views\ViewExecutable::getPager should always return a plugin that extends \Drupal\views\Plugin\views\pager\PagerPluginBase so I don't think that will be the problem.

I don't see why this would break all those tests, but it looks like this patch did cause them.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Ah, it looks like the tests are broken in the same way in #3013746: Layout Attributes from textfield to textarea, so probably not this issues's fault. RTBC it is.

  • swentel committed fcd8902 on 8.x-3.x
    Issue #3017604 by mr.baileys, borisson_, swentel: Incorrect view mode...
swentel’s picture

Status: Reviewed & tested by the community » Fixed

Wow, that's a cool one. You could have toggled "Use this configuration on every page. Otherwise the default view mode is used as soon as you browse away from the first page of this view." which would fix the behaviour you were seeing. However, I agree that the page check is nicer with that line :)

Committed and pushed, thanks!

Status: Fixed » Closed (fixed)

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