Unsafe deconstruction for PHP 8+

Created on 24 May 2024, 7 months ago
Updated 13 June 2024, 6 months ago

Problem/Motivation

In line 472 of default_content/src/Normalizer/ContentEntityNormalizer.php, there is an insufficiently guarded deconstruction.

if (isset($component['configuration']['id'])) {
          // This is only valid for inline_block.
          [$component_type, $component_bundle] = explode(PluginBase::DERIVATIVE_SEPARATOR, $component['configuration']['id']);

Although this should always deconstruct in a perfect world, there are situations where another contributed module or other unpredictable source assigns an incorrect value to $component['configuration']['id']. When the id key exists but it cannot be exploded into at least 2 items, a warning in PHP 8+ is issued:

[warning] Undefined array key 1 ContentEntityNormalizer.php:472

Steps to reproduce

In my case, the problem occurs with something called 'system_breadcrumb_block' from claro_breadcrumbs and bootstrap_barrio_breadcrumbs.

Although a typical $component['configuration']['id'] has value such as "field_block:node:special_page:field_main_area" or "field_block:node:special_page:field_hero_image", these modules assign an string such as "system_breadcrumb_block", "local_tasks_block", or "page_title_block".

Proposed resolution

Although this problem could be avoided by solving the erroneous id values in other modules, it seems unnecessary not to make this module's code as robust as possible. I'm not even sure plugin names technically must have the format '$component_type:$component_bundle' because it is so commonly not the case.

One option would be to allow the mistaken block to be processed erroneously. Obviously, that might not be the most responsible. In my case, it doesn't seem to actually cause any problems with the export even when $component_type is not technically a component type. In my case, the following has been causing no problems:

[$component_type, $component_bundle] = array_pad(explode(PluginBase::DERIVATIVE_SEPARATOR, $component['configuration']['id']), 2, null);

Otherwise, maybe we should handle the error?

🐛 Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

🇯🇵Japan neptuneDG

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

Comments & Activities

Production build 0.71.5 2024