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:

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)?

Command icon 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

pdureau created an issue. See original summary.

just_like_good_vibes’s picture

Answer : 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_name in typed_data array values of StringPropType, will allow each machine_name field property to be available as a source plugin and declared as a string.

just_like_good_vibes’s picture

Status: Active » Needs review

Now 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.

just_like_good_vibes’s picture

pdureau’s picture

So, machine_name types data was added to StringPropType instead of MachineNamePropType.

I will have a look.

pdureau’s picture

Let's rename machine_name by identifier and MachineNamePropType by IdentifierPropType.

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:

--- a/modules/ui_patterns_legacy/src/PropConverter.php
+++ b/modules/ui_patterns_legacy/src/PropConverter.php
@@ -25,7 +25,7 @@ class PropConverter {
         '$ref' => 'ui-patterns://links',
       ],
       'machine_name' => [
-        '$ref' => 'ui-patterns://machine_name',
+        '$ref' => 'ui-patterns://identifier',
       ],
       'number' => $this->convertNumber($setting),
       'radios' => $this->convertEnum($setting),

And update the tests in:

  • modules/ui_patterns_devel/tests/themes/ui_patterns_devel_theme_test/components/all_errors
  • tests/modules/ui_patterns_test/components/

this will be a breaking change

Used in some theme. Example:

 $ grep -r machine_name */components/*
ui_suite_uswds/components/nav/nav.component.yml:      $ref: 'ui-patterns://machine_name'
ui_suite_uswds/components/nav_footer/nav_footer.component.yml:      $ref: 'ui-patterns://machine_name'
pdureau’s picture

Title: [2.0.0-beta4] MachineName prop & typed data API » [2.0.0-beta4] Rename MachineName to Identifier
pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs review » Reviewed & tested by the community

pdureau’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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