Machine Name element description should allow for cases where machine name uses hyphens

Created on 3 May 2019, about 6 years ago
Updated 18 February 2023, about 2 years ago

Problem/Motivation

When adding a new shortcut set, the description on the machine name field uses the machine name element default ("A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores."), but Shortcut machine names require hyphens. The machine name element validator checks the 'replace' key in the form element for '-' vs '_' and changes the validation text accordingly, but the description doesn't change accordingly (see attached screenshot). To reproduce, go to /admin/config/user-interface/shortcut/add-set and click the edit link by machine name after entering a Set name.

Before

After

Proposed resolution

Check for replace key in element in the processMachineName method of the renderer, update description text accordingly.

🐛 Bug report
Status

Needs work

Version

10.0

Component
Render 

Last updated 7 days ago

Created by

🇺🇸United States hart0554

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    As a bug it will need a test case.

  • First commit to issue fork.
  • Merge request !11948Converted #31 to an MR and added a test → (Open) created by dcam
  • 🇺🇸United States dcam

    I converted #31 to an MR and added an assertion for the updated machine name element description.

  • Pipeline finished with Success
    13 days ago
    Total: 1017s
    #482744
  • 🇺🇸United States smustgrave

    Won’t this require updating machine_name schema now too?

    Just reading the proposed solution “check replacement key…” not sure that’s been implemented.

    Title made me think that hyphens are valid machine names and is that true? What will that break

  • 🇮🇳India prashant.c Dharamshala

    prashant.c made their first commit to this issue’s fork.

  • 🇮🇳India prashant.c Dharamshala

    For this we only need to replace -with _in the replace_patternand replacekeys of the machine_nameelement.
    This will allow lowercase letters, numbers, and underscores, and the "replace" key will replace other special characters with _.

    Please review.

  • Pipeline finished with Canceled
    11 days ago
    #483648
  • Pipeline finished with Success
    11 days ago
    #483652
  • 🇺🇸United States smustgrave

    Should be a test around that change. Probably can drop the test for the description

  • 🇺🇸United States smustgrave

    Also I’m not sure hyphen is a valid machine character

  • 🇮🇳India prashant.c Dharamshala

    Will try to add test coverage, if hyphen(-) is used in the machine name, it will get replaced by underscore(_).

  • 🇺🇸United States dcam

    The issue summary explicitly says "Shortcut machine names require hyphens." If this is being undone, then justification for that needs to be given and the IS should be updated accordingly. Please ensure that proper research into this change has been performed.

  • 🇺🇸United States dcam

    Just reading the proposed solution “check replacement key…” not sure that’s been implemented.

    The IS needs to be updated. I forgot to do it. In #22 @alexpott outlined the solution: any element that overrides the replacement pattern should also override the description to describe the change. In #23 he clarified that statement to say that we don't want to get into the business of trying to build a regex parser to do that work automatically.

    Thus, the solution to this issue is to have the Shortcut's machine name element override the description and also update the machine name Element's docs to add text saying "if you override the replacement pattern, then you also need to override the description."

    Title made me think that hyphens are valid machine names and is that true?

    All I know is that the IS says: "Shortcut machine names require hyphens." And I didn't look into why, but currently the element does replace disallowed characters with hyphens. I'm guessing there's no test coverage around it since the last change made by @prashant.c didn't break anything.

  • 🇺🇸United States dcam

    I updated the IS and issue title.

    For the record, there's no restriction on using hyphens in machine names, other than what's defined in the element's replace_pattern. This is easy enough to test. Just make a Shortcut Set at /admin/config/user-interface/shortcut/add-set that contains spaces or other disallowed characters. The disallowed characters get replaced with hyphens with no problem. Save it and then view it in the config export page. There's no problem when you export the config to files either. It's saved with hyphens no problem.

  • Pipeline finished with Success
    10 days ago
    Total: 463s
    #484920
  • 🇺🇸United States dcam

    I reverted @prashant.c's changes because they were out-of-scope. Then I added more assertions that to verify that hyphenated machine names are allowed and valid, but underscores are not.

  • 🇮🇳India prashant.c Dharamshala

    Thank you, @dcam, maybe I misunderstood the issue, so now hyphens are allowed whereas underscores are not.

Production build 0.71.5 2024