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
ContextValidatorto 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
ThemeManagerInterfaceif necessary (e.g., context-based theming decisions). - Document the new alter hooks with examples and update related PHPDocs.
Remaining tasks
- Implement
getFormIds()andgetFormIdRegexes()methods inContextValidator. - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3530489-add-alter-hooks-3530489-1.patch | 4.06 KB | xavier.masson |
Issue fork gin_lb-3530489
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
Comment #2
xavier.massonComment #3
xavier.massonComment #4
xavier.massonComment #6
christian.wiedemann commentedI merged it to 3.x branch. Thanks for contributing.
Comment #8
christian.wiedemann commented