Problem/Motivation

Date AP Style's settings schema is present but not fully constrained, which prevents 100% config validation.
Drupal 10.2 introduced configuration validation constraints and #config_target so modules can strictly validate settings:
#3376195 Choice constraint for configuration schema,
#3373502 Using validation constraints via #config_target.

Steps to reproduce

  1. Install Date AP Style module
  2. Run drush config:inspect date_ap_style.settings
  3. Note configuration shows as validatable but without strict constraints
  4. Try setting invalid values like drush config:set date_ap_style.settings separator "invalid"
  5. Invalid values are accepted without validation errors
  6. (Drush 13 will still allow setting invalid config, but a future version may enable config validation. )

Proposed resolution

  • Add strict constraints to config/schema/date_ap_style.schema.yml:
    • separator: Choice with explicit options (endash, to).
    • timezone: Choice with callback to DateTimeZone::listIdentifiers (as per Drupal core's system module pattern).
    • Add missing field formatter schema definitions for timestamp_ap_style and daterange_ap_style.
    • Ensure schema defaults match defaultConfiguration().
  • Refactor settings form to use #config_target for each element so schema constraints are enforced automatically on submit.
  • Add comprehensive post-update function to:
    • Migrate legacy configuration names and structure
    • Convert string/integer boolean values to proper boolean types
    • Fix entity view display field formatter settings data types
    • Handle both fresh installations and existing sites
  • Add tests:
    • Kernel: Configuration validation with valid/invalid values.
    • Functional: UI shows inline errors when submitting invalid inputs.
  • Set/confirm minimum core version to 10.2+ (required for constraints + #config_target workflow).

Remaining tasks

  • [x] Add/adjust constraints in date_ap_style.schema.yml (separator Choice, timezone Choice callback).
  • [x] Add missing field formatter schema definitions.
  • [x] Update settings form elements to use #config_target.
  • [x] Implement comprehensive post_update function to normalize existing config and handle data type conversions.
  • [x] Deprecate date_ap_style.date_ap_style.dateapstylesettings schema .
  • [x] Align schema defaults with defaultConfiguration().
  • [x] Write Kernel tests for invalid/valid config validation.
  • [x] Ensure PHP strict types in all PHP files.
  • [x] Write Functional tests for form validation.
  • [x] Update composer.json to require core ≥10.2.

User interface changes

Simplified the default settings form by removing custom submit logic and leveraging #config_target for automatic configuration handling. Form validation now happens automatically through schema constraints.

API changes

Configuration schema now includes strict validation constraints. Sites using invalid configuration values will need to update them to valid options.

Data model changes

Boolean configuration values are now stored as proper boolean types instead of strings or integers. Legacy configurations are automatically migrated via post-update functions.


Release notes (when merged)

  • Configuration is now strictly validated using schema constraints and #config_target.
  • Boolean values in configuration are now properly typed (migrated automatically).
  • Field formatter settings in entity view displays are automatically cleaned up.
  • Sites on Drupal 10.0–10.1 must upgrade core to ≥10.2 before updating this module.
  • Invalid timezone and separator values will now trigger validation errors.
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

trackleft2 created an issue. See original summary.

trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes

trackleft2’s picture

Status: Active » Needs review
trackleft2’s picture

On initial module install, this is what I see when I run the config_inspector module drush config:inspect command

 git:(main) lando drush config:inspect date_ap_style.dateapstylesettings --detail
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------- ---------------- ------------- ------ 
  Key                                                        Status           Validatable   Data  
 ---------------------------------------------------------- ---------------- ------------- ------ 
  date_ap_style.dateapstylesettings:_core                    missing schema                       
  date_ap_style.dateapstylesettings:date_ap_style_settings   missing schema                       
 ---------------------------------------------------------- ---------------- ------------- ------ 

And on an entity view display using the timestamp_ap_style formatter.

 lando drush config:inspect core.entity_view_display.node.az_news.az_row --detail
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 --------------------------------------------------------------------------------------------------------------- ---------------- ------------- ------ 
  Key                                                                                                             Status           Validatable   Data  
 --------------------------------------------------------------------------------------------------------------- ---------------- ------------- ------ 
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.always_display_year            missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.use_today                      missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.display_day                    missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.use_all_day                    missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.timezone                       missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.cap_today                      missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.display_time                   missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.time_before_date               missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.display_noon_and_midnight      missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.capitalize_noon_and_midnight   missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.hide_date                      missing schema                       
  core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.month_only                     missing schema                       
 --------------------------------------------------------------------------------------------------------------- ---------------- ------------- ------ 

And on the daterange_ap_style formatter.

lando drush config:inspect core.entity_view_display.node.az_event.az_card_alternate --detail
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------------------------------------------------------------------------- ---------------- ------------- ------ 
  Key                                                                                                                          Status           Validatable   Data  
 ---------------------------------------------------------------------------------------------------------------------------- ---------------- ------------- ------ 
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.always_display_year            missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.use_today                      missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.cap_today                      missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.display_time                   missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.time_before_date               missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.display_noon_and_midnight      missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.use_all_day                    missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.separator                      missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.timezone                       missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.display_day                    missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.month_only                     missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.hide_date                      missing schema                       
  core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.capitalize_noon_and_midnight   missing schema                       
 ---------------------------------------------------------------------------------------------------------------------------- ---------------- ------------- ------ 

Then when I run the database updates I see:

lando drush updatedb:status --format=table
 --------------- ---------------------------- ------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Module          Update ID                    Type          Description                                                                                                                                                                    
 --------------- ---------------------------- ------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  date_ap_style   migrate_and_cleanup_config   post-update   Migrate configuration and fix data types for existing installations.   This comprehensive post-update function handles:  - Migration from old config name                      
                                                             (date_ap_style.dateapstylesettings)    to new (date_ap_style.settings)  - Cleanup of invalid configuration keys  - Conversion of stringinteger values to proper boolean types  
                                                             in main config  - Conversion of stringinteger values to proper boolean types in    entity view display configs  - Handles both fresh installations and existing sites.         
 --------------- ---------------------------- ------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
lando drush updatedb -y                   
 --------------- ----------- ------------- ------------------------------------------- 
  Module          Update ID   Type          Description                                
 --------------- ----------- ------------- ------------------------------------------- 
  date_ap_style   mi          post-update   Migrate configuration and fix data types   
                  gr                        for existing installations.   This         
                  at                        comprehensive post-update function         
                  e_                        handles:  - Migration from old config      
                  an                        name (date_ap_style.dateapstylesettings)   
                  d_                          to new (date_ap_style.settings)  -       
                  cl                        Cleanup of invalid configuration keys  -   
                  ea                        Conversion of stringinteger values to      
                  nu                        proper boolean types in main config  -     
                  p_                        Conversion of stringinteger values to      
                  co                        proper boolean types in    entity view     
                  nf                        display configs  - Handles both fresh      
                  ig                        installations and existing sites.          
 --------------- ----------- ------------- ------------------------------------------- 


 // Do you wish to run the specified pending updates?: yes.                                                             

>  [notice] Update started: date_ap_style_post_update_migrate_and_cleanup_config
>  [notice] Migrated configuration from date_ap_style.dateapstylesettings to date_ap_style.settings. Cleaned up main configuration and fixed data types. Fixed data types in 12 entity view display configurations.
>  [notice] Update completed: date_ap_style_post_update_migrate_and_cleanup_config
 [success] Finished performing updates.
 lando drush config:inspect date_ap_style.dateapstylesettings --detail                       
➜  🤖 Analyzing…

 [warning] Undefined variable $all_property_paths InspectorCommands.php:259
 [warning] foreach() argument must be of type array|object, null given InspectorCommands.php:259
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ----------------------------------- ----------- ------------- ------ 
  Key                                 Status      Validatable   Data  
 ----------------------------------- ----------- ------------- ------ 
  date_ap_style.dateapstylesettings   No schema                       
 ----------------------------------- ----------- ------------- ------ 
lando drush config:inspect date_ap_style.settings --detail
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ------------------------------------------------------ --------- ------------- ------ 
  Key                                                    Status    Validatable   Data  
 ------------------------------------------------------ --------- ------------- ------ 
  date_ap_style.settings                                 Correct   100%          ✅✅  
   date_ap_style.settings:                               Correct   Validatable   ✅✅  
   date_ap_style.settings:always_display_year            Correct   Validatable   ✅✅  
   date_ap_style.settings:cap_today                      Correct   Validatable   ✅✅  
   date_ap_style.settings:capitalize_noon_and_midnight   Correct   Validatable   ✅✅  
   date_ap_style.settings:display_day                    Correct   Validatable   ✅✅  
   date_ap_style.settings:display_noon_and_midnight      Correct   Validatable   ✅✅  
   date_ap_style.settings:display_time                   Correct   Validatable   ✅✅  
   date_ap_style.settings:hide_date                      Correct   Validatable   ✅✅  
   date_ap_style.settings:month_only                     Correct   Validatable   ✅✅  
   date_ap_style.settings:separator                      Correct   Validatable   ✅✅  
   date_ap_style.settings:time_before_date               Correct   Validatable   ✅✅  
   date_ap_style.settings:timezone                       Correct   Validatable   ✅✅  
   date_ap_style.settings:use_all_day                    Correct   Validatable   ✅✅  
   date_ap_style.settings:use_today                      Correct   Validatable   ✅✅  
 ------------------------------------------------------ --------- ------------- ------ 
 lando drush config:inspect core.entity_view_display.node.az_event.az_card_alternate --detail
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ------------------------------------------------------------------------------------------------------------------------------------------------------- --------- ------------- ------ 
  Key                                                                                                                                                     Status    Validatable   Data  
 ------------------------------------------------------------------------------------------------------------------------------------------------------- --------- ------------- ------ 
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings                                                          Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.always_display_year                                      Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.cap_today                                                Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.capitalize_noon_and_midnight                             Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.display_day                                              Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.display_noon_and_midnight                                Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.display_time                                             Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.hide_date                                                Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.month_only                                               Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.separator                                                Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.time_before_date                                         Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.timezone                                                 Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.use_all_day                                              Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_event.az_card_alternate:content.field_az_event_date.settings.use_today                                                Correct   Validatable   ✅✅  

 lando drush config:inspect core.entity_view_display.node.az_news.az_row --detail            
➜  🤖 Analyzing…

 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ---------------------------------------------------------------------------------------------------------------------------------------- --------- ------------- ------ 
  Key                                                                                                                                      Status    Validatable   Data  
 ---------------------------------------------------------------------------------------------------------------------------------------- --------- ------------- ------ 
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings                                                        Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.always_display_year                                    Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.cap_today                                              Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.capitalize_noon_and_midnight                           Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.display_day                                            Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.display_noon_and_midnight                              Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.display_time                                           Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.hide_date                                              Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.month_only                                             Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.time_before_date                                       Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.timezone                                               Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.use_all_day                                            Correct   Validatable   ✅✅  
   core.entity_view_display.node.az_news.az_row:content.field_az_published.settings.use_today                                              Correct   Validatable   ✅✅  
trackleft2’s picture

Status: Needs review » Needs work

There are still some undone tasks.

trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Issue summary: View changes
trackleft2’s picture

Status: Needs work » Needs review

  • trackleft2 committed 1bb686e6 on 2.x
    Resolve #3542751 Add schema constraints and #config_target to make Date...

trackleft2’s picture

Version: 2.0.2 » 2.1.x-dev

  • trackleft2 committed 2d896656 on 3.0.x
    [#3542751] task: Remove deprecated date_ap_style.dateapstylesettings...
trackleft2’s picture

Status: Needs review » Fixed

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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