8/6/2023 0 Comments Drupal 8 form api example![]() There's a significant amount of work to do first to make Drupal Core happily validating its config. The same information is made available.ģ - Getting config to validate is a large work-in-progressĪs of today (June 8 2023), config constraints are not applied when saving configuration. Other options include listing only errors, or treating elements missing constraints as errors).Ĭaption: the results of running `config:inspect` on the ttings, showing validation errors due to repeated keys and a non-URL namespace.Īlternately, navigate to the GUI at Reports > Configuration inspector. (replacing ttings with the key for your desired config, or omit to see all configuration. `drush config:inspect -filter-keys=ttings -detail -list-constraints` You can use Config Inspector's command line or the module's GUI. ![]() To see if your configuration validates, first install the Configuration Inspector (`config_inspector`) module. It does not take any options.Ģ - Run the validator by using the Config Inspector module The second place we added constraints is under the `namespace` element, and it makes sure that the namespace value is a valid URL, and not blank (since the `Url` validator does not complain if the value is empty). It is necessary to tell the constraint which part of the mapping is functioning as the unique key, by passing the `labelKey` option. This will fail if someone enters two rows with the same key. The first constraint, directly under `rdf_namespaces`, states that the sequence must have unique 'prefix' elements. This element corresponds to the form element where a user can enter key|value pairs to define prefixes and RDF namespaces:Ĭaption: The configuration form for the JsonLD module, showing the widget used to set RDF Namespaces as key|value pairs. There are two places we applied constraints here, both in the `rdf_namespaces` element. The constraints are defined by the `constraints` key at various places in the schema. Label: 'If checked, ?_format=jsonld will be stripped from the end of urls in JSONLD' Here's what a config file with constraints looks like: Today we focused on simple configs, such as a module's settings, rather than more complex configs, such as field types or other extensions of base configs. That file lists all config entities that the module makes available. Here's what I learned today about implementing configuration validation:ġ - Enable validation by putting `constraints` into the schema.Ĭonstraints are the elements that make config validatable, and they go in your module's config/schema/.schema.yml file. ![]() Up to now this validation has been done in the Form API (in the form widget or form validation code), but all that validation can be bypassed when setting configuration values through other methods, such as PHP code, Drush, or (potentially in the future) JSON API. For example, you may require that users enter a positive integer, a non-empty string, or a valid date. When Drupal module builders expose configuration options, it's good to set some constraints on what values are allowed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |