Region keys should be validated

Created on 11 April 2024, 5 months ago
Updated 23 April 2024, 5 months ago

Problem/Motivation

The demo_umami install profile ships with default content to populate the site. The profile configuration ships with this for the 'full' mode of the Recipe node entity view display:

 -
        layout_id: layout_oneplusfourgrid_section
        layout_settings:
          label: ''
        components:
          cc87463d-bb75-4eca-a2d0-42f0b643f8a7:
            uuid: cc87463d-bb75-4eca-a2d0-42f0b643f8a7
            region: content
            configuration:
              id: 'field_block:node:recipe:field_media_image'
              label: 'Media Image'
              label_display: '0'
              provider: layout_builder
              context_mapping:
                entity: layout_builder.entity
                view_mode: view_mode
              formatter:
                type: entity_reference_entity_view
                label: hidden
                settings:
                  view_mode: responsive_3x2
                third_party_settings: {  }
            weight: 4
            additional: {  }

Only... according to the custom Layout plugin in Umami, the 'content' region does not exist:

layout_oneplusfourgrid_section:
  label: 'One plus four grid'
  path: layouts/oneplusfourgrid_section
  template: layout--oneplusfourgrid-section
  library: umami/oneplusfourgrid_section
  category: 'Custom grid'
  default_region: first
  icon_map:
    - [first, second, third]
    - [first, fourth, fifth]
  regions:
    first:
      label: First
    second:
      label: Second
    third:
      label: Third
    fourth:
      label: Fourth
    fifth:
      label: Fifth

The 'content' region is indeed stored in the field value, making it impossible to remove from it. When reading out JSON:API content for Layout Builder ( πŸ“Œ [PP-1] Expose Layout Builder data to REST and JSON:API Postponed ) you will see it fed back to you:

This is problematic when trying to sort and order the regions and components for JSON:API. There is no way to know from the frontend that this is either an invalid block or invalid configuration given this region doesn't actually exist.

Steps to reproduce

Install Umami profile, view the field data for an overridden layout for Recipes or the default managed layout. The 'content' region will exist in the mentioned Layout plugin that should not exist.

Proposed resolution

Validate the data before saving. If the region does not exist in the layout it is in, remove the block from the data before saving, and alert the user that the block was removed and needs to be re-added and or, the data is invalid and cannot be saved. In either case there needs to be recovery and a way to adjust it.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡ΊπŸ‡ΈUnited States kevinquillen

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

Comments & Activities

  • Issue created by @kevinquillen
  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    If the region does not exist in the layout it is in, remove the block from the data before saving, and alert the user that the block was removed and needs to be re-added and or, the data is invalid and cannot be saved.

    Would it be less harmful/destructive to first try moving the block to the first valid region that is defined, and warn the user. If there are no valid regions defined, I guess alert the user that the Layout needs a region in order to be saved (if we're not doing this already).

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    The other real issue is that since the region doesn't exist, its never rendered in the form, you can never get rid of it. It persists in the data and revisions forever.

    Maybe there could be an area at the bottom of the repo as a temp holding area for blocks with issues like that. I was primarily looking at this from JSON:API and absolutely puzzled.

Production build 0.71.5 2024