Problem/Motivation

The ContextValidator service in the gin_lb module contains hardcoded lists of form IDs and regular expressions used to determine whether a form should be styled and enhanced by Gin Layout Builder.

Currently, there is no supported way for external modules or themes to declare their own forms as part of the Layout Builder context. This limits the flexibility of Gin LB integrations and violates Drupal’s extensibility best practices.

Steps to reproduce

  • Create a custom form related to Layout Builder (e.g., a custom block configuration form).
  • Attempt to have it styled by Gin LB.
  • Observe that it is not detected by ContextValidator::isLayoutBuilderFormId() unless its ID is hardcoded.

Proposed resolution

  • Refactor ContextValidator to lazy-load the form ID and regex lists.
  • Introduce two alter hooks:
    • hook_gin_lb_context_validator_form_ids_alter(array &$form_ids)
    • hook_gin_lb_context_validator_form_id_regexes_alter(array &$regexes)
  • Invoke these hooks using ModuleHandlerInterface.
  • Allow themes to influence behavior via ThemeManagerInterface if necessary (e.g., context-based theming decisions).
  • Document the new alter hooks with examples and update related PHPDocs.

Remaining tasks

  • Implement getFormIds() and getFormIdRegexes() methods in ContextValidator.
  • Use moduleHandler->alter() to trigger hook implementations for both arrays.
  • Ensure compatibility with existing form detection logic.
  • Document the new hooks and update API reference where applicable.
  • Test with example form ID and regex added from a custom module and a theme.

User interface changes

None directly. This change affects backend extensibility only.

Introduced terminology

None.

API changes

New alter hooks introduced to extend Gin Layout Builder context form detection:

function hook_gin_lb_context_validator_form_ids_alter(array &$form_ids): void;
function hook_gin_lb_context_validator_form_id_regexes_alter(array &$regexes): void;

These allow external modules and themes to register additional forms for styling and enhancements.

Data model changes

None.

Release notes snippet

The gin_lb module now supports extending form detection logic used by ContextValidator via alter hooks. Use hook_gin_lb_context_validator_form_ids_alter() and hook_gin_lb_context_validator_form_id_regexes_alter() in your module or theme to register custom forms for Gin LB enhancements.

Issue fork gin_lb-3530489

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

xavier.masson created an issue. See original summary.

xavier.masson’s picture

Issue summary: View changes
xavier.masson’s picture

StatusFileSize
new4.06 KB
xavier.masson’s picture

Status: Active » Needs review

christian.wiedemann’s picture

Status: Needs review » Fixed

I merged it to 3.x branch. Thanks for contributing.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

christian.wiedemann’s picture

Assigned: xavier.masson » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.