Skip to content

Fix PHP 8 TypeError in block_design_regions / hidden_regions in dxpr_theme.theme #781

Description

@drale1

Summary

Issue https://www.drupal.org/project/dxpr_theme/issues/3570233

On some Drupal 10 / PHP 8+ sites upgrading from DXPR Theme 1.x to 8.x, PHP throws a TypeError in dxpr_theme.theme when certain theme settings (e.g. block design / hidden regions) are not set. It looks like theme_get_setting() can return null, and that value is passed directly into array_filter().

Steps to reproduce

  1. Start from a Drupal 10 site with:
  • PHP 8.3
  • dxpr_theme 1.x installed and set as the default theme
  1. Configure theme settings (including block / region related options).
  2. Upgrade to dxpr_theme 8.x using Composer, e.g.:
  • composer require drupal/bootstrap5
  • Enable Bootstrap 5 in the UI (/admin/appearance).
  • composer require 'drupal/dxpr_theme:^8' -w
  1. Run database updates and clear caches:
    drush updb -y
    drush cr
  2. Visit a frontend page that renders blocks in regions covered by DXPR’s block design settings.

Note: I have not been able to reliably reproduce the error myself, but another user reported it with this stack trace and pointed to dxpr_theme.theme around the block design / hidden region handling.

What is the current bug behavior?

On some configurations, after the upgrade:

  • PHP 8+ throws something like:
    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() in themes/contrib/dxpr_theme/dxpr_theme.theme on/around line 435

The reporter indicated this happens when rendering regions where DXPR’s block design settings apply.

What is the expected correct behavior?

  • Theme pages should render without PHP fatals, even when certain theme settings have never been set.
  • If a setting is missing, the theme should simply skip applying the related CSS classes / logic, instead of throwing a TypeError.

Relevant logs and/or screenshots

Example error (from another user’s local environment, paraphrased):
TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 435 of themes/contrib/dxpr_theme/dxpr_theme.theme) #0 themes/contrib/dxpr_theme/dxpr_theme.theme(435): array_filter(NULL) ...

This points at the code that reads theme_get_setting('block_design_regions') and passes it to array_filter().

Possible fixes

At a high level, the issue seems to be that:

  • theme_get_setting('block_design_regions') and theme_get_setting('hidden_regions') can return null under some configurations.
  • That value is then used directly in array_filter() (and array_keys(array_filter(...))), which is not allowed in PHP 8+.
    A possible direction for a fix would be to:
  • Add a simple type check (e.g. is_array(...)) or a default empty array before passing these values into array_filter().
  • Apply this guard in the places where dxpr_theme.theme uses theme_get_setting('block_design_regions') and theme_get_setting('hidden_regions') to build lists of regions and apply classes.
    I already have a small patch on Drupal.org’s issue [#3570233] that adds this kind of guard, and it has been tested locally by both me and the original reporter. If helpful, I can adapt that patch into a GitHub PR against the 8.x branch.

Metadata

Metadata

Assignees

Labels

8.xbugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions