Problem/Motivation
The current implementation of user_expire_role_rules makes it challenging to utilize Drupal core's configuration validation effectively. The available options are structured in a way that prevents comprehensive validation at the configuration schema level. This could lead to inconsistent or invalid configurations being saved by means other than via the Form, for example via drush config:set.
Switching to a configuration entity will provide better validation capabilities, align the implementation with modern Drupal practices, and make the rules easier to manage and extend.
Steps to reproduce
- Navigate to the configuration page for user expire role rules.
- Set up rules with inconsistent or invalid configurations (e.g., overlapping roles or missing fields).
- Save the configuration and notice the lack of validation feedback.
Proposed resolution
Convert user_expire_role_rules into a configuration entity. This approach involves:
- Using
drush generate config-entityto scaffold the necessary boilerplate code for the entity. - Defining a schema and validation logic within the configuration entity class to ensure consistent and valid configurations.
- Implementing a UI for managing the configuration entity (e.g., list builder and form handlers).
Converting these rules into configuration entities has additional benefits as well.
1. We could add more features (like fallback role, or global setting overrides for example)
2. Site owners and install profile maintainers can override/add individual config entities individually and separately from the global settings config.
Remaining tasks
- Generate the configuration entity using Drush.
- Implement the validation logic in the entity class.
- Create list builder and form handlers for the entity.
- Update the admin interface to use the new configuration entity.
- create a post_update.php implementation to update existing configuration to. the new way.
- Write tests to cover validation and UI functionality.
User interface changes
A new admin interface will be introduced for managing user_expire_role_rules. This includes:
- A list builder page to display existing rules.
- Form handlers for adding, editing, and deleting rules.
API changes
Existing APIs related to user_expire_role_rules will be deprecated or refactored to use the new configuration entity. New entity methods will be added for validation and retrieval of role expiration rules.
Data model changes
The current array-based schema for user_expire_role_rules will be replaced with a configuration entity structure. This change will involve migrating existing configurations to the new entity.
Issue fork user_expire-3495090
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
trackleft2Comment #3
trackleft2Comment #4
shelaneClosed per #3493946: Make configuration schema more validate-able