How to require a referenced block to be an inline block?

Created on 19 August 2019, almost 5 years ago
Updated 19 June 2023, about 1 year ago

Problem/Motivation

I would like to be able to create a custom block type for use with Layout Builder. For purposes of this discussion, let's say that I am creating an image slider. I have a Slider custom block type. I also have have a Slide custom block type, which consists of an image, title, and description. The Slider block type has an entity reference field called Slides which references the Slide block type.

When I create a Slider block through Layout Builder on an individual node, the Slider block is created as an Inline Block. How would I go about creating the Slides that are referenced by the Slider so that they are also created as Inline Blocks.

I currently have a test setup using Entity Browser + Inline Entity Form, which allows me to trigger the creation of Slides in the context of their Slider, but those blocks don't appear to be created as Inline Blocks. They show up in the list on the Custom block library page. However, I'm pretty sure this issue doesn't have anything to do with the specifics of the test setup, as mentioned. If I just created the blocks through the Block management interface, then referenced them using an autocomplete widget on the Slides field, it would ultimately be the same outcome.

I understand that this is happening, in either case, because there is no direct connection between the context of the Layout Builder and the creation of the Slides. I'm not sure how to bridge that gap.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States pyrello

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom very_random_man

    Just came across this whilst looking for something else and thought i'd leave a comment in case other people find this. You can get around the requirement for nasty nested entity/paragraph doom forms by making more use of sections, custom layouts and the layout options and layout builder restrictions modules.

    So for example...

    - Create a card block.
    - Set up a custom layout for the Card Group section and some layout options (see examples below) so you can add a title and a summary. I used a custom options setting which was pretty simple so i could use stuff like rich text fields.
    - You then use Layout Builder Restrictions to restrict usage of the Card block so it can only be placed in a Card Group section.

    I find this significantly simpler from a dev and UX perspective and better than the typical 'all blocks in one column with extra helpings of massive nested forms in a small column' approach. :-)

    THEME.layouts.yml

    card_group:
      class: '\Drupal\layout_options\Plugin\Layout\LayoutOptions'
      label: 'Card group'
      category: 'Whatever'
      path: templates/layouts
      template: layout--card-group
      default_region: main
      icon_map:
        - [ card-a, card-b, card-c ]
        - [ card-d, card-e, card-f ]
        - [ card-g, card-h, card-i ]
      regions:
        main:
          label: Card content
    

    THEME.layout_options.yml

    layout_option_definitions:
      card_variant:
        title: Card variant
        description: The card variant applied to all cards in this section.
        plugin: layout_options_class_select
        multi: false
        default: default
        options:
          default: Default
          button: Button
          small: Small
        layout: true
        regions: false
        weight: 1
    
      section_heading:
        title: Section heading
        description: An optional heading added to the top of the section.
        plugin: MODULE_layout_options_setting_textfield
        default: ''
        layout: true
        regions: false
        weight: -50
    
      section_summary:
        title: Section summary
        description: An optional summary for the section.
        plugin: MODULE_layout_options_setting_formatted_text
        default: ''
        layout: true
        regions: false
        weight: -40
    
    layout_options:
    
      card_group:
        section_heading: {}
        section_summary: {}
        card_variant: {}
    
    
Production build 0.69.0 2024