Provide twig template for layout builder render element and widgets

Created on 7 July 2023, over 1 year ago
Updated 28 July 2023, over 1 year 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 23 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 over 1 year ago
    Custom Commands Failed
  • @john-pitcairn opened merge request.
  • last update over 1 year 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 over 1 year 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 over 1 year 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.71.5 2024