Browser block item displayed via a theme function

Created on 21 March 2023, over 1 year ago
Updated 10 September 2024, 3 months ago

Some months ago I created a feature request and a patch to "simplify the browser form": https://www.drupal.org/project/layout_builder_browser/issues/3306544 Add options to simplify the browser form Closed: outdated

I am now working on another project and the customer's request around the browser form are slightly different. I realise that the approach I followed is still restrictive to the option listed.

I would suggest that block items in the browser are displayed using a theme function so it is easier for any custom module to override the default template.
I also suggest to integrate the preview image with the image style to ease the uniformisation of the images.
Finally, as requested in another ticket Allow a small description underneath thumbnail Fixed , adding a short description can also be very useful. By default it would be displayed under the block label but it is very simple by overriding the template to make it appear somewhere else (as a tooltip for example).

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France vbouchet

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

Comments & Activities

  • Issue created by @vbouchet
  • @vbouchet opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇫🇷France vbouchet

    Please find a MR which tries to have as little opinion as possible on how the browser should be displayed. It should not have impact on existing sites given the default image style is "Original" and description field is optional.

    • vbouchet committed cfec02e3 on 8.x-1.x
      Issue #3349340 by vbouchet: Browser block item displayed via a theme...
  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 3 months ago
  • Hi,

    I tried to use the template added by the commit "cfec02e3". I found that the template is a sub-template per block and is not used by default.

    In a custom module:
    I have added the theme with "hook_theme()"
    With "hook_layout_builder_browser_alter()" have added the theme the sub elements as such:

    /**
     * Implements hook_layout_builder_browser_alter().
     */
    function CUSTOM_MODULE_layout_builder_browser_alter(array &$build, array $context) {
      foreach ($build['block_categories'] as $category_key => &$category) {
        if ($category_key === 'default') {
          foreach ($category['links'] as $block_key => &$block) {
            $build['block_categories'][$category_key]['links'][$block_key]['#theme'] = 'layout_builder_browser_block';
          }
        }
      }
    }
    

    The template is called for every block type but, unfortunately, I did not manage to get the correct variables for the template "layout-builder-browser-block.html.twig".
    In the hook_theme I tried both defining variables or render element.

    Am I misunderstanding the intention of this template ? Did someone succeed to render the layout builder browser modal with a template ?

    Thanks,

Production build 0.71.5 2024