By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.2.x
Introduced in version:
10.2.0
Issue links:
Description:
A new config schema data type, called machine_name, has been added to core. As the name suggests, this constraint can be used to indicate that not just any string is allowed, but a string shaped like a machine name.
The default validation constraints can be found in the definition of the new machine_name data type:
# Machine-readable identifier that can only contain certain characters.
machine_name:
type: string
label: 'Machine name'
constraints:
Regex: '/^[a-z0-9_]+$/'
Length:
max: 64
(Note that this did not add a new MachineName validation constraint because that is not flexible enough — unfortunately not all machine names are alike!)
How to use?
Generally speaking:
- Before
-
mapping: id: type: string label: 'ID' - After
-
mapping: id: type: machine_name label: 'ID'
Non-standard machine names
And cases where the machine name has a different set of allowed characters or a different maximum length can then override it:
- Specifying a
machine_namemax length other than64 -
media.type.*: type: config_entity label: 'Media type' mapping: id: type: machine_name label: 'Machine name' constraints: Length: # Media type IDs are specifically limited to 32 characters. # @see \Drupal\media\MediaTypeForm::form() max: 32 - Specifying a
machine_namethat allows something else than alphanumeric characters & underscores -
system.menu.*: type: config_entity label: 'Menu' mapping: id: type: machine_name label: 'ID' # Menu IDs are specifically limited to 32 characters, and allow dashes but not # underscores. # @see \Drupal\menu_ui\MenuForm::form() constraints: Regex: '/^[a-z0-9-]+$/' Length: max: 32
Impacts:
Module developers