Custom block types are missing from add block - other

Created on 26 July 2024, 9 months ago
Updated 29 July 2024, 8 months ago

Problem/Motivation

My custom / inline block types are missing from the layout edit page when I try to add a block.

I have a lot of custom block types, like 'Text', 'Image', 'Hero', .. as you can see in screenshot problem-1.png.
I have a node type 'node_layoutbuilder' that has layoutbuilder enabled, you can see the layoutbuilder field display settings in problem-2.png. I have added some of my inline block types as promoted blocks, as you can see in problem-3.png. Those appear fine no problem on the layout edit page, add block in the Promoted tab (add-block-promoted.png).

In the Blocks available for placement (all layouts & regions) section I don't want much of the default blocks, So Ive set most of the items to Restrict all existing & new Block blocks, like: block, chaos tools, custom blocks, devel, eu cookie compliance, forms, user, geolocation, help, lb+, views, menus, navigation, system, webform.

But I did want most of my custom block types to be available, except some. That is why I set the option to Restrict specific Inline blocks blocks: for both Inline blocks as Custom block types (because all my block types appear in both those sections). Then I selected the few that I do not want, expecting that I would end up seeing the not selected ones. See screenshot problem-5.png.

But none of the not selected block types show up on the Add block - Other section on layout edit page. See screenshot add-block-other.png

Did I do something wrong in settings ? Or is there a bug in the code somewhere ?

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium flyke

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

Comments & Activities

  • Issue created by @flyke
  • πŸ‡§πŸ‡ͺBelgium flyke
  • πŸ‡§πŸ‡ͺBelgium flyke

    I tried setting Inline blocks and Custom block types to Allow all existing & new Custom block types blocks. After saving, I've got these errors both twice:

    • User warning: The following theme is missing from the file system: toolbar in Drupal\Core\Extension\ExtensionPathResolver->getPathname() (line 63 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).
    • Deprecated function: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\Core\Extension\ExtensionPathResolver->getPath() (line 85 of core/lib/Drupal/Core/Extension/ExtensionPathResolver.php).

    When I go to the layout edit page and add a block then, only a few show up, not the ones that I actually want.

  • πŸ‡§πŸ‡ͺBelgium flyke

    Not sure if its helpful, this is the devel output for the 'Text' block type. Again: that shows up and works as Promoted block, but I cannot seem to get it shown on the Other tab, just like all my other custom block types.

  • πŸ‡§πŸ‡ͺBelgium flyke

    I might have figured it out by copparing modules/contrib/lb_plus/src/Element/LayoutBuilderPlusUI.php to modules/contrib/layout_builder_browser/src/Controller/BrowserController.php on how to list blocks.
    Testing this patch in a moment.

  • πŸ‡ΊπŸ‡ΈUnited States tim bozeman

    Hmm strange... If you disable LB+ do you get the results your after in regular Layout Builder? Is it a Layout Builder Restrictions problem? I thought we had it dialed in to where LB+ is acting the same as regular Layout Builder. πŸ€”

  • πŸ‡§πŸ‡ͺBelgium flyke

    If I disable LB+ then I do get the results I'm after: I see the blocks that I'm missing in lb_plus. BUT this is not form a clean Layout Builder.
    I enabled lb_plus for testing in a project that already had lots of layoutbuilder settings and configuration from other contrib modules:

    • bootstrap_layout_builder
    • bootstrap_styles
    • layout_builder_blocks
    • layout_builder_browser
    • layout_builder_modal
    • layout_builder_restrictions

    So it might be from one of them. I'll see if its possible to test disabling most of those modules in my test project. If I succeed, I will report back.

  • πŸ‡§πŸ‡ͺBelgium flyke

    I disabled layout_builder_restrictions, layout_builder_browser, layout_builder_modal.
    Without lb_plus: custom inline block types are available
    With lb_plus: custom inline block types are not available inside Edit layout -> Add block (+ icon in the bottom bar) -> 'Other' tab.

    My custom inline blocks are available if I make specific adjustments to lb_plus/src/Element/LayoutBuilderPlusUI.php
    If I change this:

        if ($layout_builder_type === 'layout_block') {
          // Include fields from the parent entity.
          $parent_definitions = $this->blockManager->getFilteredDefinitions('layout_builder', $this->getPopulatedContexts($section_storage), [
            'section_storage' => $section_storage,
          ]);
          foreach ($parent_definitions as $name => $parent_definition) {
            if (str_contains($name, 'field_block:')) {
              $definitions[$name] = $parent_definition;
            }
          }
        }

    Into (adding extra new code below):

        // Add field blocks.
        if ($layout_builder_type === 'layout_block') {
          // Include fields from the parent entity.
          $parent_definitions = $this->blockManager->getFilteredDefinitions('layout_builder', $this->getPopulatedContexts($section_storage), [
            'section_storage' => $section_storage,
          ]);
          foreach ($parent_definitions as $name => $parent_definition) {
            if (str_contains($name, 'field_block:')) {
              $definitions[$name] = $parent_definition;
            }
          }
        }
    
        // Add custom inline blocks.
        if ($layout_builder_type === 'entity') {
          $parent_definitions = $this->blockManager->getFilteredDefinitions('layout_builder', $this->getPopulatedContexts($section_storage), [
            'section_storage' => $section_storage,
            'list' => 'inline_blocks',
          ]);
          foreach ($parent_definitions as $name => $parent_definition) {
            if (str_contains($name, 'inline_block:')) {
              $definitions[$name] = $parent_definition;
            }
          }
        }

    If I do that then my custom inline block types are available.

    I actually added this bit of code to the MR from #3404515 ✨ Improve Icon Selection/Upload Active because I needed both this fix as well as the icon improvements to set an icon for every block type, not just promoted blocks. And I could not get both to work using a patch for the issue here and an MR for the issue there, so I did not include this patch from this issue in my project and instead only included the MR from #3404515 ✨ Improve Icon Selection/Upload Active which now fixes both problems. Maybe not ideal so any feedback welcome if there is a better way.

Production build 0.71.5 2024