Add an OR condition

Created on 6 November 2024, 16 days ago

Problem/Motivation

There is no option for specifying that only one of multiple Contexts should pass for a block to be visible. The request was made previously in https://www.drupal.org/project/layout_builder_context/issues/3356905 🌱 Should something still be visible if all contexts fail AND 'all must pass' is unchecked? Fixed and https://www.drupal.org/project/layout_builder_context/issues/3356636 Allow editor to select 'all' or 'only one' pass condition for a set of Contexts Fixed .
The only option is boolean "All Contexts must pass" and unchecking that option makes the block display if all Contexts fail, which is not ideal for anyone looking for ANY of the Contexts to pass for the block to be visible.

Steps to reproduce

Install this module and configure a block in Layout Builder where the only option is boolean "All Contexts must pass." There is no "At least one Context should pass" option.

Proposed resolution

I will create an MR where I have swapped the single "All contexts must pass" checkbox with radio buttons for "Context Conditions" and have included the new option, "At least one Context must pass," which is effectively an "OR" condition.

No database update should be required because the previous boolean values map to their current behaviours: 0 => All must fail, 1 => All must pass.

To change the previous default unchecked behaviour (block would display when all Contexts failed) to the new "At least one Context must pass" condition, search your config yml for "context_all_must_pass: 0" and change the value to 2 then do a drush cim (or manually and selectively change them in the UI for those layouts).

Remaining tasks

Review code and merge MR if acceptable.

User interface changes

There will be 3 options under Context Conditions:
All Contexts must fail (default behaviour when previous checkbox was unchecked)
At least one Context must pass
All Contexts must pass

API changes

None

Data model changes

None

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada darkodev

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024