field_required_context
Field Required Context provides a shared API for Drupal modules to share and evaluate when a field is required based on context (publish vs draft, imports, composite fields, etc.), instead of duplicating custom logic.
Project Status
This project is in early development and will attempt to bridge the gap between the Field Required Context Initiative and contrib modules wishing to adopt it.
Features
Field Required Context introduces a reusable, service-based API for context-aware field requiredness. Rather than each module reinventing “required when publishing” or “required when a sub-field is active,” this module provides:
- A validation context object describing the current operation (for example, publish vs draft, import vs UI submit, composite enabled or disabled).
- A central manager service that answers: “Is this field required in this context?”
- A validation constraint that uses the manager to enforce requiredness consistently across fields.
- Integration patterns for modules that implement their own ideas of “required” (such as Require on Publish, composite fields like Name and Address, conditional logic, imports, and more).
This module is primarily for developers and site builders who maintain complex editorial workflows or field types and want predictable, shared, context-aware validation instead of one-off implementations in each module.
Post-Installation
After installing this module, there is no end-user UI and no immediate change for site builders. Field Required Context is an API module.
Developers and maintainers should:
- Review the README and any provided example code to understand the validation context object and requiredness manager service.
- Integrate their modules by:
- Contributing additional information to the validation context where relevant (for example, publish operations, composite activation flags, import operations).
- Consulting the manager service when deciding if a field should be treated as required in a given context.
- Optionally attaching the provided validation constraint to entities or fields to centralize enforcement.
Configuration steps and integration recipes will be documented as the API stabilizes and early adopters (for example Require on Publish, Name, Address, Webform, Migrate, Feeds) begin to use it.
Additional Requirements
There are no external PHP libraries or third-party APIs required beyond Drupal core. Individual integrations may introduce their own dependencies in their respective modules.
Integrated modules
Field Required Context becomes more useful as other modules adopt it. Consider adopting it into your module. If you are a contrib maintainer, have a look at #3561148: [Meta] Contrib Adoption: How Modules Integrate with Field Required Context.
As integrations mature, this section will be updated with concrete versions and links.
Similar projects
Many contrib modules today implement their own context-aware requiredness:
- Require on Publish enforces “required on publish” rules.
- Name and Address define their own internal completeness rules for composite fields.
- Webform includes its own condition and validation engine.
- Conditional Fields, Paragraphs, Migrate, Feeds, and others each have isolated logic for when fields are effectively required.
Field Required Context does not replace these modules. Instead, it aims to provide a shared, generic API and validation layer that these and other projects can use to express their rules in a consistent way, reducing duplication and conflicts.
Supporting this Module
Support for this module is best provided through:
- Opening issues in the issue queue to report bugs, propose improvements, and share integration use cases.
- Contributing patches, merge requests, and documentation updates.
- Participating in related community discussions and initiatives around field requiredness and validation in Drupal core and contrib.
Community Documentation
Community documentation and planning for this module are coordinated through the Field Required Context Initiative project on Drupal.org. That project will host:
- Meta issues and roadmaps for API design and core adoption.
- Links to example integrations in modules such as Require on Publish, Name, and others.
- References to BoF notes, architectural discussions, and any external demos or walkthroughs.
As the module and initiative evolve, additional links to tutorials, talks, and demo environments will be added here.