Provide twig template for layout builder render element and widgets

Created on 7 July 2023, 12 months ago
Updated 28 July 2023, 11 months ago

Problem/Motivation

For a frontend theme wishing to provide its own layout builder element widgets, toolbars, etc, the structure of the layout builder render element can be very limiting, forcing some very hacky and fragile overrides.

There does not appear to be a specific theme hook, preprocess or template for themers to cleanly override the element output. You either get to muck around with the very generic and nested "container" and "link" theme hooks, add a #pre_render handler and manipulate the render array directly, or override and extend the render element class to implement a dedicated theme and template yourself.

Proposed resolution

Implement hook_theme() for layout builder module, provide specific twig templates for the layout render element, the section configure links, and the section/block add links.

Feature request
Status

Postponed

Version

11.0 🔥

Component
Layout builder 

Last updated about 3 hours ago

Created by

🇳🇿New Zealand John Pitcairn

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

Comments & Activities

  • Issue created by @John Pitcairn
  • 🇫🇮Finland lauriii Finland

    Seems like a great idea 👍 Would be happy to review a patch/MR if you have time to create one.

  • 🇳🇿New Zealand John Pitcairn

    This would affect any existing contrib that adds a #pre_render callback to modify the element, like section_library. Are render elements expected to provide any stability in this respect?

  • last update 11 months ago
    Custom Commands Failed
  • @john-pitcairn opened merge request.
  • last update 11 months ago
    Custom Commands Failed
  • 🇳🇿New Zealand John Pitcairn

    That's a start - I added templates for the main layout builder element, and an included template for the add-section elements, with most of the logic moved into those:

    @layout_builder/layout-builder.html.twig
    @layout_builder/layout-builder--add-section.html.twig

    Not ready for review beyond that (and general approach). I'll move onto adding templates for the individual sections and their widget links within the next few days.

    This WILL break any contrib currently adding a #pre_render function to alter the output. The way to do that with this in place will be to implement hook_preprocess_layout_builder(), hook_preprocess_layout_builder__add_section(), etc. Themes can just override the templates, preprocess, or both.

    We may need to move attribute definitions back into LayoutBuilder::layout() if contrib expect to have those in preprocess.

  • last update 11 months ago
    29,879 pass, 3 fail
  • 🇳🇿New Zealand John Pitcairn

    We may need to move attribute definitions back into LayoutBuilder::layout() if contrib expect to have those in preprocess.

    Or implement template_preprocess_layout_builder. Maybe add an explicit theme hook for each template instead of just using twig include(), so those have an explicit preprocess with accessible attributes and variables.

  • Status changed to Postponed 11 months ago
  • 🇳🇿New Zealand John Pitcairn

    I think the best course of action might be to postpone this until the current initiative to improve the layout builder experience is well bounded.
    Switching to a theme function and adding twig templates now is likely to collide with everything happening there.
    See 🌱 [META] Layout builder editorial improvements Active

    Feedback?

Production build 0.69.0 2024