Allow numeric limit per region

Created on 4 July 2023, over 1 year ago
Updated 5 July 2023, over 1 year ago

Problem/Motivation

It can be useful to limit paragraphs numerically.

Use cases from my own experience:

  1. "boxy" CSS grid layouts where every one grid child = one region must contain exactly one child, to enforce top and bottom alignment across the entire grid.
    Example grid with size-aligned children
  2. "Description - List" layouts
    E.g. a 2 column layout where the left column must contain exactly one description or title paragraph and the right column contains multiple items.
    Example layout from one of my projects with multiple list items on left and single description on right (on large screens)

Proposed resolution

Add an integer config setting numeric_limit per region

disallowed_types:
  layout_name:
    region_name:
      negate: true
      paragraph_types: { }
      numeric_limit: 123

In case of nested layouts: The limit validator will count direct children only. A nested layout counts as one component.

User interface changes

Add number input below bundle checkboxes for every region.

Data model changes

Yes, see proposed resolution

Other notes

It is technically possible to limit number of children on the paragraph host field. Similar to a bundle filter on the host field, this setting can not overrule the host field setting.

📌 Task
Status

Needs work

Version

1.0

Component

Code

Created by

🇦🇹Austria hudri Austria

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

Comments & Activities

  • Issue created by @hudri
  • Status changed to Needs work over 1 year ago
  • 🇦🇹Austria hudri Austria

    I just pushed a draft implemention on the feature fork repo. It works all quite well except one thing:

    Duplicate component does not emit any event and therefore bypasses the numeric limit :-(

  • @hudri opened merge request.
  • 🇦🇹Austria hudri Austria
  • 🇭🇺Hungary nagy.balint

    Hi!

    This part of the code

    if (empty($disallowed_types[$parent_layout][$region]['paragraph_types'])) {
          return;
        }

    Was done cause of https://www.youtube.com/shorts/Zmx0Ou5TNJs

    Apart from that, maybe we just need to explain this limitation with duplicate on the UI somewhere, and we can still have this feature?

  • 🇦🇹Austria hudri Austria

    I totally agree with avoiding nesting ifs, but we no longer can use that guard clause with the early exit because we also need to check for the numeric limit.

    You are the maintainer, so it is your decision when you want to merge. But I personally would not advise to merge it yet. Even if we add a message at the form, this is only visible to site architects. An editor using the builder would not know that limitation.

    (This also is the reason why I created the draft MR, if somebody really needs that feature, it can be added with composer-patches and https://git.drupalcode.org/project/layout_paragraphs_limit/-/merge_requests/10.patch)

Production build 0.71.5 2024