Problem/Motivation

I'd love to see validation constraints show up in the Config Inspector UI — see #2164373: [META] Untie config validation from form validation — enables validatable Recipes, decoupled admin UIs … 🤓

In Drupal core, we only have:

# A UUID.
uuid:
  type: string
  label: 'UUID'
  constraints:
    Uuid: {}

… but hopefully more things will get that: #2952037: [meta] Add constraints to all simple configuration 🤞

So far only the CDN contrib module uses this extensively: #2969065: Use typed config validation constraints for validation of cdn.settings simple config.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

  1. drush support for validatability %#10
  2. UI support for validatability %
  3. drush support for listing validation constraints#27
  4. UI support for listing validation constraints → since #25: +

API changes

Data model changes

Comments

Wim Leers created an issue. See original summary.

vuil’s picture

Version: 8.x-1.3 » 8.x-1.x-dev
wim leers’s picture

FYI: https://www.drupal.org/project/ckeditor5 also uses validation constraints extensively!

wim leers’s picture

And now Drupal core uses it (because CKEditor 5 was moved into Drupal core). The Group module is also adopting it over at #2925819: Ability to force using a scheme instead of scheme-relative URLs.

kristiaanvandeneynde’s picture

Yes please! I've just started using constraints on config entities in Group and it's a great way to make sure the business logic is respected both when managing these entities through the UI and through code.

vuil’s picture

Version: 8.x-1.x-dev » 2.1.x-dev
Category: Task » Feature request
wim leers’s picture

Title: Expose constraints in config schema in Config Inspector UI » Expose validation constraints (and validatability %) in Config Inspector UI
Assigned: Unassigned » wim leers
StatusFileSize
new97.86 KB

I've started building this! 🥳

I've got it working locally already. I'm building on top of #3359418: Expose validation constraint violations in Config Inspector UI and drush command. I'm starting out with Validatability % first, but that means I've got 95% of what we need in place.

Sneak preview:

wim leers’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Configuration schema
StatusFileSize
new13.44 KB

1/4 done.

  1. $ vendor/bin/drush config:inspect --only-error
     --------------------- ---------- ------------- ---------- 
      Key                   Status     Validatable   Data      
     --------------------- ---------- ------------- ---------- 
      editor.editor.cke4    1 errors                           
      media.settings        Correct    17%           1 errors  
      system.theme.global   Correct    38%           1 errors  
      tour.tour.cdn-ui      8 errors                           
      update.settings       Correct    8%            1 errors  
     --------------------- ---------- ------------- ---------- 
    
  2. Nothing in core is 100% validatable, but when we start making more things validatable, this new flag will be really helpful:
    $ vendor/bin/drush config:inspect --only-error --invalidatability-is-error
     ----------------------------------------------------------- ---------- ------------- ---------- 
      Key                                                         Status     Validatable   Data      
     ----------------------------------------------------------- ---------- ------------- ---------- 
      automated_cron.settings                                     Correct    0%            Valid     
      automatic_updates.settings                                  Correct    20%           Valid     
      block.block.claro_breadcrumbs                               Correct    27%           Valid     
      block.block.claro_content                                   Correct    27%           Valid     
      block.block.claro_help                                      Correct    27%           Valid     
    …
      editor.editor.basic_html                                    Correct    69%           Valid     
    
    …
      system.menu.footer                                          Correct    40%           Valid     
      system.menu.main                                            Correct    40%           Valid     
      system.menu.tools                                           Correct    40%           Valid     
    …
      views.view.who_s_new                                        Correct    18%           Valid     
      views.view.who_s_online                                     Correct    17%           Valid     
     ----------------------------------------------------------- ---------- ------------- ---------- 
    
  3. Let's look at only a few:
    $ vendor/bin/drush config:inspect --only-error --invalidatability-is-error --filter-keys=media.settings,system.theme.global
     --------------------- --------- ------------- ---------- 
      Key                   Status    Validatable   Data      
     --------------------- --------- ------------- ---------- 
      media.settings        Correct   17%           1 errors  
      system.theme.global   Correct   38%           1 errors  
     --------------------- --------- ------------- ---------- 
    
  4. Let's add detail:
    $ vendor/bin/drush config:inspect --only-error --invalidatability-is-error --filter-keys=media.settings,system.theme.global --detail
     ------------------------------ --------- ------------- ----------------------------------------------------- 
      Key                            Status    Validatable   Data                                                 
     ------------------------------ --------- ------------- ----------------------------------------------------- 
      _core                          Correct   NOT                                                                
      _core.default_config_hash      Correct   NOT                                                                
      icon_base_uri                  Correct   NOT                                                                
      iframe_domain                  Correct   NOT                                                                
      oembed_providers_url           Correct   NOT                                                                
      media.settings:iframe_domain   Correct                 This value should be of the correct primitive type.  
      favicon                        Correct   NOT                                                                
      favicon.mimetype               Correct   NOT                                                                
      favicon.path                   Correct   NOT                                                                
      favicon.url                    Correct   NOT                                                                
      features                       Correct   NOT                                                                
      logo                           Correct   NOT                                                                
      logo.path                      Correct   NOT                                                                
      logo.url                       Correct   NOT                                                                
      system.theme.global:logo.url   Correct                 This value should be of the correct primitive type.  
     ------------------------------ --------- ------------- ----------------------------------------------------- 
    

This looks surprisingly simple but took me MULTIPLE DAYS to put together! 😱

wim leers’s picture

gábor hojtsy’s picture

The code updates look good :) The only thing I am stuck on is whether "invalidatability" is a word or a good word at least? When I tried googling for it, Google suggested "invalidate ability" which means an entirely different thing. Should it be "--strict-validation" or only "--strict" even?

wim leers’s picture

But "strict" already has a particular meaning in the config schema world: \Drupal\KernelTests\KernelTestBase::$strictConfigSchema:

  /**
   * Set to TRUE to strict check all configuration saved.
   *
   * @see \Drupal\Core\Config\Development\ConfigSchemaChecker
   *
   * @var bool
   */
  protected $strictConfigSchema = TRUE;

IMHO "validatability" is just fine. Yes, it's kinda like "cacheability" in how little it was used. But it's perfectly valid English. And there is prior use of it beyond Drupal — for example \Symfony\Component\HttpFoundation\Response::isValidateable().

How about --invalidatable-is-error or --not-validatable-is-error? 🤔😊

wim leers’s picture

Issue summary: View changes
StatusFileSize
new5.93 KB
new19.3 KB
new467.95 KB

Now validatability is shown in the UI 👍

Next up: showing validation constraints.

Status: Needs review » Needs work

The last submitted patch, 14: 3216089-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

StatusFileSize
new1.95 KB
new19.16 KB

Thanks to #14 I noticed that media.settings has the type uri yet is marked as not validatable. That is not correct.

The problem:

  • interface UriInterface extends PrimitiveInterface → note that this does not inherit StringInterface
  • yet class Uri extends StringData implements UriInterface
  • which means that due to class StringData extends PrimitiveBase implements StringInterface
  • Uri implements StringInterface too 🤪

I didn't account for that in ::computeNodeValidatability(). Fixed.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new3.28 KB
new22.39 KB

Oops, #14 and #16 were missing the new class that #10 added.

gábor hojtsy’s picture

I was thinking --error-if-invalid but that would be about the validation result not that it can be validated or not. Hm. --error-if-not-validateable could be an option but I'm still not 100% convinced :D It has a very particular spelling that may be easy to get wrong.

wim leers’s picture

Maybe "strict" is fine. 🤔 Because we'd eventually want \Drupal\KernelTests\KernelTestBase::$strictConfigSchema to actually validate things too.

So … perhaps this is even appropriate! 😄

I'll update the patch and open a core issue for doing exactly that.

wim leers’s picture

Status: Needs review » Needs work
+++ b/src/Commands/InspectorCommands.php
@@ -104,19 +128,36 @@ class InspectorCommands extends DrushCommands {
+          if ($detail) {
+            foreach ($raw_validatability->getValidatabilityPerPropertyPath() as $property_path => $is_validatable) {
+              // Skip validatable property paths.
+              if ($onlyError && $invalidatability_is_error && $is_validatable === TRUE) {
+                continue;
+              }
+              $rows[$property_path] = ['key' => $property_path, 'status' => $status, 'validatability' => $is_validatable ? dt('Validatable') : dt('NOT'), 'data' => NULL];
+            }
+          }
+          // Continue to validating the data: even with incomplete
+          // validatability that is valuable to check.

🐛 This means that first "detail" rows are generated for each property path … and then we continue on toward validating, which results in output like this:

$ vendor/bin/drush config:inspect --invalidatability-is-error --filter-keys=media.settings --detail
 ------------------------------------------ --------- ------------- ----------------------------------------------------- 
  Key                                        Status    Validatable   Data                                                 
 ------------------------------------------ --------- ------------- ----------------------------------------------------- 
  media.settings:_core                       Correct   NOT                                                                
  media.settings:_core.default_config_hash   Correct   NOT                                                                
  media.settings:icon_base_uri               Correct   NOT                                                                
  media.settings:iframe_domain               Correct   Validatable                                                        
  media.settings:oembed_providers_url        Correct   Validatable                                                        
  media.settings:standalone_url              Correct   NOT                                                                
  media.settings:_core                       Correct                 Valid                                                
  media.settings:_core.default_config_hash   Correct                 Valid                                                
  media.settings:icon_base_uri               Correct                 Valid                                                
  media.settings:iframe_domain               Correct                 This value should be of the correct primitive type.  
  media.settings:oembed_providers_url        Correct                 Valid                                                
  media.settings:standalone_url              Correct                 Valid                                                
 ------------------------------------------ --------- ------------- ----------------------------------------------------- 

👆 Each property path is listed TWICE: once for "validatability" detail, once for "data validity" detail.

That should of course be combined.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new4.01 KB
new23.95 KB

This is better:

$ vendor/bin/drush config:inspect --invalidatability-is-error --filter-keys=media.settings --detail
 ------------------------------------------- --------- ------------- ----------------------------------------------------- 
  Key                                         Status    Validatable   Data                                                 
 ------------------------------------------- --------- ------------- ----------------------------------------------------- 
  media.settings                              Correct   33%           1 errors                                             
   media.settings:_core                       Correct   NOT           Valid                                                
   media.settings:_core.default_config_hash   Correct   NOT           Valid                                                
   media.settings:icon_base_uri               Correct   NOT           Valid                                                
   media.settings:iframe_domain               Correct   Validatable   This value should be of the correct primitive type.  
   media.settings:oembed_providers_url        Correct   Validatable   Valid                                                
   media.settings:standalone_url              Correct   NOT           Valid                                                
 ------------------------------------------- --------- ------------- ----------------------------------------------------- 

I took the liberty of slightly changing how --detail works. Rather than showing only details, I'm now also keeping the row for the containing config. Because that gives you a valuable high-level perspective: the % of validatability and the number of errors. Given the increase in information provided, I think this is a reasonable change.

Also fixed the PHPLint error (which does not occur on PHP 8, hence I missed it).

wim leers’s picture

StatusFileSize
new3.83 KB
new23.87 KB

I changed it to use --strict but ran into

$ vendor/bin/drush config:inspect --strict --filter-keys=media.settings --detail
PHP Fatal error:  Uncaught TypeError: Drush\Preflight\PreflightArgs::setStrict(): Argument #1 ($strict) must be of type bool, null given in /Users/wim.leers/core/vendor/drush/drush/src/Preflight/PreflightArgs.php:453
Stack trace:
#0 [internal function]: Drush\Preflight\PreflightArgs->setStrict(NULL)
#1 /Users/wim.leers/core/vendor/drush/drush/src/Preflight/ArgsPreprocessor.php(85): call_user_func(Array, NULL)

… turns out drush reserves this argument: \Drush\Preflight\PreflightArgs::isStrict() 🤷‍♀️

So --strict-validation it is!

wim leers’s picture

StatusFileSize
new6.54 KB
new22.31 KB

Fixed a typo from #22 … and refactored the logic to support collecting all validation constraints.

This actually allowed me to delete code! 😅🥳 (Turns out I was computing certain things twice…)

No UI yet: not in Drush nor in the web UI.

wim leers’s picture

StatusFileSize
new6.54 KB
new22.41 KB

Noticed a bug introduced in #16 while verifying that the output for #23 still matched that of earlier patch iterations (it did — until #16 as expected, which is how I spotted this bug) — I inverted the condition there but forgot about one of the documented edge cases: BooleanInterface. Correctly handling that again results in significantly higher percentage of validatability, because a lot of config schemas use type: boolean.

wim leers’s picture

StatusFileSize
new519.26 KB
new2.1 KB
new23.46 KB

I do not yet see how the list of validation constraints can sanely be shown on the Overview or the List view. But I can see a way for the Tree view:

(Also fixed a missing use from #24 — splitting up in atomic commits allows for easy mistakes 🙈)

wim leers’s picture

Issue summary: View changes
StatusFileSize
new2.75 KB
new34.74 KB
new33.21 KB

… but I really believe that such a bulleted list just does not give enough context. I think symbols can provide a lot of clarity here, without the need for adding a lot of additional words:

P.S.: I went all the way, and made this work well in RTL contexts too:

wim leers’s picture

Assigned: wim leers » Unassigned
StatusFileSize
new5.09 KB
new27.08 KB

And now, the ability to list constraints using --list-constraints in Drush:

  1. Let's look at my module's config:
    $ vendor/bin/drush config:inspect --filter-keys=cdn.settings
     -------------- --------- ------------- ------- 
      Key            Status    Validatable   Data   
     -------------- --------- ------------- ------- 
      cdn.settings   Correct   36%           Valid  
     -------------- --------- ------------- ------- 
    
  2. Let's add detail:
    $ vendor/bin/drush config:inspect --filter-keys=cdn.settings --detail
     ----------------------------------------- --------- ------------- ------- 
      Key                                       Status    Validatable   Data   
     ----------------------------------------- --------- ------------- ------- 
      cdn.settings                              Correct   36%           Valid  
       cdn.settings:                            Correct   NOT           Valid  
       cdn.settings:_core                       Correct   NOT           Valid  
       cdn.settings:_core.default_config_hash   Correct   NOT           Valid  
       cdn.settings:farfuture                   Correct   NOT           Valid  
       cdn.settings:farfuture.status            Correct   Validatable   Valid  
       cdn.settings:langcode                    Correct   NOT           Valid  
       cdn.settings:mapping                     Correct   NOT           Valid  
       cdn.settings:mapping.conditions          Correct   NOT           Valid  
       cdn.settings:mapping.domain              Correct   Validatable   Valid  
       cdn.settings:mapping.type                Correct   NOT           Valid  
       cdn.settings:scheme                      Correct   Validatable   Valid  
       cdn.settings:status                      Correct   Validatable   Valid  
       cdn.settings:stream_wrappers             Correct   NOT           Valid  
       cdn.settings:stream_wrappers.0           Correct   Validatable   Valid  
     ----------------------------------------- --------- ------------- ------- 
    
  3. Let's list the constraints too:
    $ vendor/bin/drush config:inspect --filter-keys=cdn.settings --detail --list-constraints
     ----------------------------------------- --------- ------------- ------- ----------------------------------------------------------------------------- 
      Key                                       Status    Validatable   Data    Validation constraints                                                       
     ----------------------------------------- --------- ------------- ------- ----------------------------------------------------------------------------- 
      cdn.settings                              Correct   36%           Valid                                                                                
       cdn.settings:                            Correct   NOT           Valid                                                                                
       cdn.settings:_core                       Correct   NOT           Valid                                                                                
       cdn.settings:_core.default_config_hash   Correct   NOT           Valid                                                                                
       cdn.settings:farfuture                   Correct   NOT           Valid                                                                                
       cdn.settings:farfuture.status            Correct   Validatable   Valid   Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint  
       cdn.settings:langcode                    Correct   NOT           Valid                                                                                
       cdn.settings:mapping                     Correct   NOT           Valid                                                                                
       cdn.settings:mapping.conditions          Correct   NOT           Valid                                                                                
       cdn.settings:mapping.domain              Correct   Validatable   Valid   Drupal\cdn\Plugin\Validation\Constraint\CdnDomainConstraint                  
                                                                                Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint  
       cdn.settings:mapping.type                Correct   NOT           Valid                                                                                
       cdn.settings:scheme                      Correct   Validatable   Valid   Drupal\cdn\Plugin\Validation\Constraint\CdnSchemeConstraint                  
                                                                                Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint  
       cdn.settings:status                      Correct   Validatable   Valid   Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint  
       cdn.settings:stream_wrappers             Correct   NOT           Valid                                                                                
       cdn.settings:stream_wrappers.0           Correct   Validatable   Valid   Drupal\cdn\Plugin\Validation\Constraint\CdnStreamWrapperConstraint           
                                                                                Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint  
     ----------------------------------------- --------- ------------- ------- ----------------------------------------------------------------------------- 
    
  4. Great, now let's limit it to errors only:
    $ vendor/bin/drush config:inspect --filter-keys=cdn.settings --detail --list-constraints --only-error
     ----- -------- ------------- ------ ------------------------ 
      Key   Status   Validatable   Data   Validation constraints  
     ----- -------- ------------- ------ ------------------------ 
    
  5. That listed nothing because the config schema is valid and all data is valid. So now let's enable the strict validation mode:
    $ vendor/bin/drush config:inspect --filter-keys=cdn.settings --detail --list-constraints --only-error --strict-validation
     ----------------------------------------- --------- ------------- ------- ------------------------ 
      Key                                       Status    Validatable   Data    Validation constraints  
     ----------------------------------------- --------- ------------- ------- ------------------------ 
      cdn.settings                              Correct   36%           Valid                           
       cdn.settings:                            Correct   NOT           Valid                           
       cdn.settings:_core                       Correct   NOT           Valid                           
       cdn.settings:_core.default_config_hash   Correct   NOT           Valid                           
       cdn.settings:farfuture                   Correct   NOT           Valid                           
       cdn.settings:langcode                    Correct   NOT           Valid                           
       cdn.settings:mapping                     Correct   NOT           Valid                           
       cdn.settings:mapping.conditions          Correct   NOT           Valid                           
       cdn.settings:mapping.type                Correct   NOT           Valid                           
       cdn.settings:stream_wrappers             Correct   NOT           Valid                           
     ----------------------------------------- --------- ------------- ------- ------------------------ 
    

I think/hope this proves that this all works great now. Let's switch to the example I used for showing the validatability before: media.settings:

$ vendor/bin/drush config:inspect --filter-keys=media.settings --detail --list-constraints --only-error --strict-validation
 ------------------------------------------- --------- ------------- ----------------------------------------------------- -------------------------------------------------------- 
  Key                                         Status    Validatable   Data                                                  Validation constraints                                  
 ------------------------------------------- --------- ------------- ----------------------------------------------------- -------------------------------------------------------- 
  media.settings                              Correct   43%           1 errors                                                                                                      
   media.settings:                            Correct   NOT           Valid                                                                                                         
   media.settings:_core                       Correct   NOT           Valid                                                                                                         
   media.settings:_core.default_config_hash   Correct   NOT           Valid                                                                                                         
   media.settings:icon_base_uri               Correct   NOT           Valid                                                                                                         
   media.settings:iframe_domain               Correct   Validatable   This value should be of the correct primitive type.   Drupal\Core\Validation\Plugin\Validation\Constraint\Pr  
                                                                                                                            imitiveTypeConstraint                                   
 ------------------------------------------- --------- ------------- ----------------------------------------------------- -------------------------------------------------------- 

That's the same command as the one above, just replacing cdn.settings with media.settings. Makes sense to me!

IMHO this is ready now. An idea for a follow-up could be to distinguish between inherited constraints vs local constraints — that would make it clear that for example the _core key (which is present in both cdn.settings and media.settings's Drush output) actually is of the type _core_config_info — so adding a validation constraint there would fix it everywhere.

wim leers’s picture

Another follow-up would be to map the FQCNs to the equivalent types:

  • \Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint would become PrimitiveType because of
     * @Constraint(
     *   id = "PrimitiveType",
     *   label = @Translation("Primitive type", context = "Validation")
     * )
    
  • \Drupal\cdn\Plugin\Validation\Constraint\CdnDomainConstraint would become CdnDomain because of
     * @Constraint(
     *   id = "CdnDomain",
     *   label = @Translation("CDN domain", context = "Validation"),
     * )
    
  • and so on
  • … but that's really just a nice-to-have compared to today, where this information is still painfully difficult to access.

wim leers’s picture

Issue summary: View changes
gábor hojtsy’s picture

Status: Needs review » Needs work

Looks great overall! I think there is a disconnect where we say the data is not validatable and then we say the data is valid :) Can we unbreak the terminology mismatch there?

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new549.41 KB
new2.04 KB
new27.51 KB

Good call!

I was not happy about that either.

Having worked on #3361534: KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate in the mean time, I think I know how to distinguish: Valid (when actually properly validatable) vs Correct primitive type (when no real validation constraints are present, only primitive type is being checked):

$ vendor/bin/drush config:inspect --filter-keys=system.theme.global --detail --strict-validation
 --------------------------------------------------------- --------- ------------- ----------------------------------------------------- 
  Key                                                       Status    Validatable   Data                                                 
 --------------------------------------------------------- --------- ------------- ----------------------------------------------------- 
  system.theme.global                                       Correct   53%           1 errors                                             
   system.theme.global:                                     Correct   NOT           Correct primitive type                               
   system.theme.global:_core                                Correct   Validatable   Valid                                                
   system.theme.global:_core.default_config_hash            Correct   Validatable   Valid                                                
   system.theme.global:favicon                              Correct   NOT           Correct primitive type                               
   system.theme.global:favicon.mimetype                     Correct   NOT           Correct primitive type                               
   system.theme.global:favicon.path                         Correct   NOT           Correct primitive type                               
   system.theme.global:favicon.url                          Correct   NOT           Correct primitive type                               
   system.theme.global:favicon.use_default                  Correct   Validatable   Valid                                                
   system.theme.global:features                             Correct   NOT           Correct primitive type                               
   system.theme.global:features.comment_user_picture        Correct   Validatable   Valid                                                
   system.theme.global:features.comment_user_verification   Correct   Validatable   Valid                                                
   system.theme.global:features.favicon                     Correct   Validatable   Valid                                                
   system.theme.global:features.node_user_picture           Correct   Validatable   Valid                                                
   system.theme.global:logo                                 Correct   NOT           Correct primitive type                               
   system.theme.global:logo.path                            Correct   NOT           Correct primitive type                               
   system.theme.global:logo.url                             Correct   Validatable   This value should be of the correct primitive type.  
   system.theme.global:logo.use_default                     Correct   Validatable   Valid                                                
 --------------------------------------------------------- --------- ------------- ----------------------------------------------------- 

and in the UI:

What do you think?

andypost’s picture

Thank you Wim! It's very helpful and require to fix previous commit...

But when I'm looking at report in browser/drush the amount of duplicated Correct primitive type makes my eyes skip errors because errors are shorter and less visible (skimmable)

As this value is displayed for every non-error line it could be added to "legend" (above or below table) to prevent printing expected defaults on each line.

On fresh core install 10.1.x it shows only 2 errors and no performance affected

$ time drush config:inspect --only-error  --list-constraints --detail
 ------------------------------- --------- ------------- ----------------------------------------------------- ------------------------------------------------------------- 
  Key                             Status    Validatable   Data                                                  Validation constraints                                       
 ------------------------------- --------- ------------- ----------------------------------------------------- ------------------------------------------------------------- 
  system.theme.global             Correct   41%           1 errors                                                                                                           
   system.theme.global:logo.url   Correct   Validatable   This value should be of the correct primitive type.   Drupal\Core\Validation\Plugin\Validation\Constraint\Primiti  
                                                                                                                veTypeConstraint                                             
  update.settings                 Correct   14%           1 errors                                                                                                           
   update.settings:fetch.url      Correct   Validatable   This value should be of the correct primitive type.   Drupal\Core\Validation\Plugin\Validation\Constraint\Primiti  
                                                                                                                veTypeConstraint                                             
 ------------------------------- --------- ------------- ----------------------------------------------------- ------------------------------------------------------------- 
real	0m 2.66s
user	0m 2.40s
sys	0m 0.23s

btw I can't install module for 11.x branch)

+++ b/src/Commands/InspectorCommands.php
@@ -104,43 +138,113 @@ class InspectorCommands extends DrushCommands {
+          $validatability = dt('@validatability%', ['@validatability' => intval($raw_validatability->computePercentage() * 100)]);
...
       $rows[$name] = ['key' => $name, 'status' => $status, 'validatability' => $validatability, 'data' => $data];

Moreover without this patch the variable is undefined in current 2.1.x branch

gábor hojtsy’s picture

Status: Needs review » Needs work

I agree with @andypost that a shorter result would be better with a legend if needed, especially in the drush result.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new143.71 KB
new382.16 KB
new4.28 KB
new28.72 KB

Adding a legend is trivial per https://symfony.com/doc/current/components/console/helpers/table.html#sp.... We could choose to add it at the top or bottom.

But … \Consolidation\OutputFormatters\FormatterManager::write()'s unavoidable call to \Consolidation\OutputFormatters\FormatterManager::validateAndRestructure() unfortunately forcefully requires every row to contain the columns that all other rows have.

After a LOT of searching and trial and error I found a way to make it work. But this only allows us putting the legend at the top. (Which is probably preferable anyway.) This is the result:

$ vendor/bin/drush config:inspect --filter-keys=media.settings --strict-validation --detail
 Legend for Data: 
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 -------------------------------- --------- ------------- ------------------------------------- 
  Key                              Status    Validatable   Data                                 
 -------------------------------- --------- ------------- ------------------------------------- 
  media.settings                   Correct   43%           1 errors                             
   media.settings:                 Correct   NOT           ✅❓                                 
   media.settings:_core            Correct   NOT           ✅❓                                 
   media.settings:_core.default_   Correct   NOT           ✅❓                                 
  config_hash                                                                                   
   media.settings:icon_base_uri    Correct   NOT           ✅❓                                 
   media.settings:iframe_domain    Correct   Validatable   This value should be of the correct  
                                                           primitive type.                      
   media.settings:oembed_provide   Correct   Validatable   ✅✅                                 
  rs_url                                                                                        
   media.settings:standalone_url   Correct   Validatable   ✅✅                                 
 -------------------------------- --------- ------------- ------------------------------------- 

Note that the legend only appears when needed:

$ vendor/bin/drush config:inspect --filter-keys=media.settings --strict-validation
 ---------------- --------- ------------- ---------- 
  Key              Status    Validatable   Data      
 ---------------- --------- ------------- ---------- 
  media.settings   Correct   43%           1 errors  
 ---------------- --------- ------------- ---------- 

and

$ vendor/bin/drush config:inspect --filter-keys=media.settings --strict-validation --detail --fields=key,status,validatability
 ------------------------------------------- --------- ------------- 
  Key                                         Status    Validatable  
 ------------------------------------------- --------- ------------- 
  media.settings                              Correct   43%          
   media.settings:                            Correct   NOT          
   media.settings:_core                       Correct   NOT          
   media.settings:_core.default_config_hash   Correct   NOT          
   media.settings:icon_base_uri               Correct   NOT          
   media.settings:iframe_domain               Correct   Validatable  
   media.settings:oembed_providers_url        Correct   Validatable  
   media.settings:standalone_url              Correct   Validatable  
 ------------------------------------------- --------- ------------- 

I also made it stand out visually:

Finally, I made this work in the UI too:

andypost’s picture

Status: Needs review » Reviewed & tested by the community

It looks great!

andypost’s picture

StatusFileSize
new45.44 KB

It looks good even on light terminal

gábor hojtsy’s picture

StatusFileSize
new28.37 KB

Rerolled following #3361559: Config inspection should wipe relevant caches to always get up-to-date results. Let's make sure it passes our smoke tests.

  • 89100229 committed on 2.1.x
    Issue #3216089 by Wim Leers, Gábor Hojtsy, andypost, vuil: Expose...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Yay, committed! We can refine this forward as needed.

wim leers’s picture

AWESOME! 😊🥳🙏

I already started working on what I said in #27 and #28:

An idea for a follow-up could be to distinguish between inherited constraints vs local constraints — that would make it clear that for example the _core key (which is present in both cdn.settings and media.settings's Drush output) actually is of the type _core_config_info — so adding a validation constraint there would fix it everywhere.

+

Another follow-up would be to map the FQCNs to the equivalent types:

  • \Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint would become PrimitiveType because of
     * @Constraint(
     *   id = "PrimitiveType",
     *   label = @Translation("Primitive type", context = "Validation")
     * )
    
  • \Drupal\cdn\Plugin\Validation\Constraint\CdnDomainConstraint would become CdnDomain because of
     * @Constraint(
     *   id = "CdnDomain",
     *   label = @Translation("CDN domain", context = "Validation"),
     * )
    
  • and so on
  • … but that's really just a nice-to-have compared to today, where this information is still painfully difficult to access.

Stay tuned!

kristiaanvandeneynde’s picture

Ooh, shiny. Nice work!

ronaldtebrake’s picture

Awesome work, looking forward to using this!

wim leers’s picture

wim leers’s picture

Status: Fixed » Closed (fixed)

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