"Expose all fields as blocks to Layout Builder" feature not as efficient as it could be

Created on 23 July 2024, about 2 months ago

Problem/Motivation

Trying to fix another issue I was debugging code in the 10.3.x/11.x feature "Expose all fields as blocks to Layout Builder". The FieldBlockDeriver->getFieldMap() isn't cleaning up the array as effectively as it could be.

Steps to reproduce

Drupal\layout_builder\Plugin\Derivative\FieldBlockDeriver->getFieldMap(), line 198 has the following:

        $field_map[$entity_type_id][$field_name]['bundles'] = array_intersect($field_info['bundles'], $layout_bundles[$entity_type_id]);

        // If no bundles are using Layout Builder, remove this field from the
        // field map.
        if (empty($field_info['bundles'])) {
          unset($field_map[$entity_type_id][$field_name]);
        }

The comparison for `empty()` is not checking the array that has been altered, but instead checking the in memory version from when the array loop was created. Can be confirmed with debugging tools, or checking output of ->getFieldMap().

Proposed resolution

Replace empty($field_info['bundles']) with empty($field_map[$entity_type_id][$field_name]['bundles']).

Remaining tasks

PR to follow.

User interface changes

None.

Introduced terminology

None.

API changes

->getFieldMap() would return less items after the change, but the items would be the expected ones.

Data model changes

None.

Release notes snippet

Further reduced the automatically derived blocks for layout builder.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡¦πŸ‡ΊAustralia nterbogt

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

Comments & Activities

Production build 0.71.5 2024