Problem/Motivation
MachineNamePropType has a schema inherited from #3385452: Add machine_name setting type :
['type' => 'string', 'pattern' => '^[A-Za-z]+\w*$'],
Which is the intersection between:
- Drupal machine name data type: https://www.drupal.org/node/2954832
- HTML value type for ID attributes: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id
However, we are not leveraging the constraints related to Drupal machine name data type yet: we are not using typed_data like boolean does:
#[PropType(
id: 'boolean',
label: new TranslatableMarkup('Boolean'),
description: new TranslatableMarkup('Matches only two special values: true and false.'),
default_source: 'checkbox',
schema: ['type' => 'boolean'],
priority: 1,
typed_data: ['boolean']
)]
Because we didn't find any field type with a machine_name field properties in Core.
Proposed resolution
Do we add typed_data: ['machine_name'] to MachineNamePropType ?
If yes, how do we test it?
If no, is it the opportunity to drop the compatibility with Drupal machine name data type and embrace totally the HTML ID format (so, allowing - and maybe some other characters)?
Issue fork ui_patterns-3477287
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
Comment #2
just_like_good_vibesAnswer : no we won't add
typed_data: ['machine_name']to the MachineNamePropType,instead we will add machine_name to the typed_data of StringPropType.
This mechanism is only used for source derivers.
typed_datavalue in PHP Attributes of prop types, allow to declare that a Drupal typed data value, can be put in the prop type that is declaring the typed data. Here we have a machine_name drupal typed data that can go into a string prop type.Furthermore, with the mechanism in place, specifying
machine_nameintyped_dataarray values of StringPropType, will allow each machine_name field property to be available as a source plugin and declared as a string.Comment #4
just_like_good_vibesNow about HTML IDs. After some web search queries and reading:
- HTML ids could be any unicode character without spaces according to the supposed "standard". See [this link](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) for example.
- In practice, we want html ids to be used as CSS identifiers with CSS or JS. this adds some restrictions. See [this other link](https://developer.mozilla.org/en-US/docs/Web/CSS/ident) for example.
i pushed the work :
- The regex has been extended.
- I did a rapid check of unhandled simple typed data from core, and i found 'machine_name' and 'filter_format'. I added them to the string prop type php attributes, allowing for more derived field prop than before.
Comment #5
just_like_good_vibesComment #6
pdureau commentedSo,
machine_nametypes data was added toStringPropTypeinstead ofMachineNamePropType.I will have a look.
Comment #7
pdureau commentedLet's rename
machine_namebyidentifierandMachineNamePropTypebyIdentifierPropType.This prop type comply with: https://developer.mozilla.org/en-US/docs/Web/CSS/ident
See also: https://developer.mozilla.org/en-US/docs/Glossary/Identifier
It would be nice to mention those URL in description and/or comment.
And update the converter:
And update the tests in:
this will be a breaking change
Used in some theme. Example:
Comment #8
pdureau commentedComment #9
pdureau commentedComment #11
pdureau commented