Form API States configs
The module is designed for setting up Form API #States over configuration.
Installation
Install the module as you would normally install a contributed Drupal module. Visit https://www.drupal.org/node/1897420 for further information.
Configuration
- Go to Form States Configurations page (path
/admin/structure/form-states-config). - Hit 'Add Form States config' link.
- In 'Form ID' field put ID of a form which requires form states adjustments.
- In 'Form States' field add form states.
- Hit 'Save' button.
Example
Let's imagine user account has "Contact settings" (contact) and "Locale settings" (timezone) fields. "Administrator" (administrator) user role is only user role for which "Contact settings" and "Locale settings" fields should be shown on User Registration form. Create new Form States Configuration with next values:
- Form ID: user_register_form
- Form States:
contact:
visible:
:input[name="roles[administrator]"]:
- checked: TRUE
timezone:
visible:
:input[name="roles[administrator]"]:
- checked: TRUE
For more examples visit https://www.drupal.org/docs/drupal-apis/form-api/conditional-form-fields.
Notes:
1. Value for "Form States" must have a valid YAML format.
2. If it requires to add #states to nested array, for example $form['field_region']['widget']['#states'] then use field_region.widget.
3. Created configurations are exportable. Use `drush cim` to do that. Each of configuration will be exported to the config directory as form_states_config.form_states_config.[form_id].yml files.
References:
- https://www.drupal.org/docs/drupal-apis/form-api/conditional-form-fields
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Releases
| Version | Type | Core | Release date | |
|---|---|---|---|---|
| 1.0.0-beta1 | Pre-release | Dec 2, 2023 | ||
| 1.0.0-alpha1 | Pre-release | Apr 13, 2023 |