Wim Leers
Senior Principal Software Engineer
's Drupal Acceleration Team
What's this about really? ๐
What's this about really? ๐
era | storage | blobbiness | |
---|---|---|---|
2004 | variable table | extremely | ๐ |
2012 | YAML files | diffable | ๐ค๐ |
2013 | [โฆ] + schema | introspectable | ๐ค๐ก |
2014 | config table + [โฆ] | unchanged | ๐๏ธ |
2017 | [โฆ] + [โฆ] + constraints | validatable | โ |
Trend: more structure
type: uuid
๐
the only validatable config type
๐ฑ
๐
type: uuid
use
type: uuid
definition
type: uuid
Data | Types | |||
---|---|---|---|---|
Config | Storage | Perceived | ||
'f962b8c7-
4c74-4100-
b6de-08e6a65ff43d' | uuid | string | UUID | ๐ |
'https://oembed.com/
providers.json' | uri | string | URL | ๐ |
'' | uri | string | ๐คช | ๐ |
intent | shape | semantics |
Validators needed! ๐
It gets worse.
Data | Types | |||
---|---|---|---|---|
Config | Storage | Perceived | ||
'f962b8c7-
4c74-4100-
b6de-08e6a65ff43d' | uuid | string | UUID | ๐ |
'https://oembed.com/
providers.json' | uri | string | URL | ๐ |
'' | uri | string | ๐คช | ๐ |
'first-uuid' | uuid | string | ๐คช | ๐ฑ |
Validators are not executed today.
๐ซ
๐คทโโ๏ธ
config_split
, config_filter
โฆ
>95% of config types not validatable
#3324984 ๐ test to track this %
Every test checks schema โฆ
โฆ but does not validate!
#3361534 ๐ validate()
More config validatable!
type: config_dependencies
block.block.*:plugin
More validation constraints to reuse!
ValidKeys:
<infer>
PluginExists:
plugin.manager.block
ExtensionName: {}
ExtensionExists:
module
ConfigExists: {}
Issue tags:
Since 2.1.1
You can start using this today!
ValidatableConfigFormBase
which extends \Drupal\Core\Form\ConfigFormBase
ValidatableConfigFormBase
instead of ConfigFormBase
ValidatableConfigFormBase
which extends \Drupal\Core\Form\ConfigFormBase
ValidatableConfigFormBase
instead of ConfigFormBase
ConfigEvents::SAVE
subscriber to validate your config
constraints
*.schema.yml
files
Analyze your entire site
drush config:inspect --format=csv > ~/Desktop/core.csv
$ drush config:inspect --filter-keys=user.settings --detail --list-constraints
Legend for Data:
โ
โ โ Correct primitive type, detailed validation impossible.
โ
โ
โ Correct primitive type, passed all validation constraints.
------------------------------------------ --------- ------------- ------ ---------------------------------
Key Status Validatable Data Validation constraints
------------------------------------------ --------- ------------- ------ ---------------------------------
user.settings Correct 74% โ
โ
user.settings: Correct NOT โ
โ
user.settings:_core Correct NOT โ
โ
user.settings:_core.default_config_hash Correct NOT โ
โ
user.settings:anonymous Correct NOT โ
โ
user.settings:cancel_method Correct NOT โ
โ
user.settings:langcode Correct NOT โ
โ
user.settings:notify Correct NOT โ
โ
user.settings:notify.cancel_confirm Correct Validatable โ
โ
โฃ PrimitiveType: { }
user.settings:notify.password_reset Correct Validatable โ
โ
โฃ PrimitiveType: { }
โฆ
user.settings:notify.status_activated Correct Validatable โ
โ
โฃ PrimitiveType: { }
user.settings:notify.status_blocked Correct Validatable โ
โ
โฃ PrimitiveType: { }
user.settings:notify.status_canceled Correct Validatable โ
โ
โฃ PrimitiveType: { }
user.settings:password_reset_timeout Correct NOT โ
โ
user.settings:password_strength Correct Validatable โ
โ
โฃ PrimitiveType: { }
user.settings:register Correct NOT โ
โ
user.settings:verify_mail Correct Validatable โ
โ
โฃ PrimitiveType: { }
------------------------------------------ --------- ------------- ------ ------------------------
user.settings:
type: config_object
label: 'User settings'
mapping:
anonymous:
type: label
label: 'Name'
+ constraints:
+ NotBlank: []
+ Regex:
+ pattern: '/[[:alnum:]]+/'
+ message: 'Using only emojis is not allowed because it may not be supported in all contexts.'
user.schema.yml
-class AccountSettingsForm extends ConfigFormBase {
+class AccountSettingsForm extends ValidatableConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
- $this->config('user.settings')
- ->set('anonymous', $form_state->getValue('anonymous'))
- ->set('register', $form_state->getValue('user_register'))
- ->set('password_strength', $form_state->getValue('user_password_strength'))
- ->set('verify_mail', $form_state->getValue('user_email_verification'))
- ->set('cancel_method', $form_state->getValue('user_cancel_method'))
- ->set('notify.status_activated', $form_state->getValue('user_mail_status_activated_notify'))
- ->set('notify.status_blocked', $form_state->getValue('user_mail_status_blocked_notify'))
- ->set('notify.status_canceled', $form_state->getValue('user_mail_status_canceled_notify'))
- ->save();
+ /**
+ * {@inheritdoc}
+ */
+ protected static function mapFormValuesToConfig(FormStateInterface $form_state, Config $config): Config {
+ switch ($config->getName()) {
+ case 'user.settings':
+ $config->set('anonymous', $form_state->getValue('anonymous'))
+ ->set('register', $form_state->getValue('user_register'))
+ ->set('password_strength', $form_state->getValue('user_password_strength'))
+ ->set('verify_mail', $form_state->getValue('user_email_verification'))
+ ->set('cancel_method', $form_state->getValue('user_cancel_method'))
+ ->set('notify.status_activated', $form_state->getValue('user_mail_status_activated_notify'))
+ ->set('notify.status_blocked', $form_state->getValue('user_mail_status_blocked_notify'))
+ ->set('notify.status_canceled', $form_state->getValue('user_mail_status_canceled_notify'));
+ }
+ return $config;
+ }
META | #2164373 ๐ โคต |
Required values | #3364109 |
Required keys | #3364108 |
Validate in tests | #3361534 |
Metadata for rich UX | #2949888 |
Which config changes have caused outages for YOU? ๐ซต