An empty views pager offset field can cause a PHP type error to be triggered.

Created on 18 May 2023, about 1 year ago
Updated 6 March 2024, 4 months ago

Problem/Motivation

I came across an intriguing bug in Drupal 10 views when configuring pager options. If the offset field is left empty, it triggers a PHP type error. In Drupal 10, the expected value for the offset field is 0, but when it is empty, it becomes offset: null instead.

TypeError: Cannot assign null to property Drupal\views\Plugin\views\query\QueryPluginBase::$offset of type int in Drupal\views\Plugin\views\query\QueryPluginBase->setOffset() (line 152 of core/modules/views/src/Plugin/views/query/QueryPluginBase.php).

Steps to reproduce

1. Enable views and views_ui module with D10.
2. Pick a views then set the `pager` - items to display (leave it as default), offset (default is 0, remove it so that the field is empty)
3. Save it (Click 'Apply'))
4. The PHP TypeError can be found in PHP logs.

Proposed resolution


Update all places that call setOffset to cast the offset to an integer

MR 4707 is the canonical source for this issue.

Remaining tasks



Action #17

User interface changes

None

API changes

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated less than a minute ago

Created by

🇦🇺Australia pandaski

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

Comments & Activities

Production build 0.69.0 2024