Use a readonly class for Pager value object

Created on 22 April 2024, 8 months ago
Updated 5 July 2024, 6 months ago

Problem/Motivation

In PHP 8.1 and above we can use read only properties. The primary benefit of this is to reduce side effects from values changing after they are initialized, but it also allows us to reduce boilerplate, as we can safely make these properties public and remove the need for a getter method.

In PHP 8.2 and above we can mark a whole class as read only, ensuring that all properties on the class are read only.

Value objects are great candidates for readonly classes. The \Drupal\Core\Pager\Pager class is a prime example of one that can be converted.

Steps to reproduce

Proposed resolution

  • Mark \Drupal\Core\Pager\Pager as readonly
  • Declare $totalPages, $currentPage, $totalItems and $limit as public
  • Deprecate getters
  • Update template_preprocess_pager to access public properties directly

Remaining tasks

How do we provide backwards compatibility for a class becoming readonly? Probably need a whole new class and deprecate the old class.

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Baseย  โ†’

Last updated about 10 hours ago

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia mstrelan

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024