Fix Layout Builder compatibility for Media Gallery

Created on 5 August 2025, 10 days ago

Problem/Motivation

The Media Gallery module is currently not fully compatible with Layout Builder. Specifically, galleries rendered within Layout Builder layouts will throw exceptions and not display because layout builder changes how the render array are structured

Steps to reproduce

1. Install and Enable Layout Builder
2. Enable layout builder in Structure -> Media Gallery -> Manage display
3. Create a media gallery
4. View the gallery
5. observe that the page cannot be rendered due to errors.

Proposed resolution

- Add detection for when a media gallery is being rendered inside Layout Builder.
- Add a utility method (`MediaGalleryUtilities::getLayoutBuilderImagesField()`) to extract the images field from nested Layout Builder sections.
- Use this images field reference in the preprocessing function to apply the same logic (e.g., pagination, reversing) regardless of whether Layout Builder is used.
- Add logging for cases where the images field is not present in the Layout Builder layout.
- Move processing of non image render arrays to the field preprocessor method
- Adjust template and test expectations accordingly.

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

✨ Feature request
Status

Active

Version

3.0

Component

Default

Created by

πŸ‡ΊπŸ‡ΈUnited States circuitcipher

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