Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295783

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

$
0
0

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

Strictly type the $offset parameter in setOffset to int
Update all places that call setOffset to cast the offset to an integer

MR 4707 is the canonical source for this issue.

Remaining tasks

Agree on approach
Tests
Action #17

User interface changes

None

API changes

setOffset requires an integer


Viewing all articles
Browse latest Browse all 295783


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>