Views Block Display skips preBlockBuild() call on ajax rebuild

Created on 30 October 2015, over 8 years ago
Updated 13 June 2024, 15 days ago

Problem/Motivation

The \Drupal\views\Plugin\views\display\Block::preBlockBuild() method is responsible for manipulating the view before it is rendered by the corresponding block plugin. The block plugin itself actually calls this method, however blocks cannot show exposed filters without using ajax, and the ajax rebuild for views will not call the preBlockBuild() method.

As a practical example, blocks can override the number of results per page for a view, however if they leverage ajax rebuild, on the first rebuild (which is also used for pagers) the view will be rendered without the block's overrides. If the default view shows 50 per page, and the override shows 5, the first ajax call will result in the view now showing 50 instead of 5.

Proposed resolution

Add new function to view Block.php display plugin (getBlockFromAjaxRequest) that runs when ajax is used in a view block.
Adding new function (preparePreview) to DisplayPluginInterface

Previous solution
The views/ajax controller needs to consult the block when rebuilding block displays. Doing this generically is likely to be a bit convoluted.

Remaining tasks



Change record (maybe)
Review
Commit

User interface changes

NA - working ajax for view blocks now.

API changes

NA

Data model changes

NA

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated less than a minute ago

Created by

🇺🇸United States EclipseGc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024