Problem/Motivation
The switch shortcut form (/user/N/shortcuts) displays the 'id' field when the associated text field 'label' is not visible.
I first saw this in a 9.5 installation, confirmed in 10.x.dev on simplytest.me.
Steps to reproduce
On a default Drupal installation:
- Create a second set of shortcuts
- Grant 'switch shortcut sets' ("Select any shortcut set") to authenticated users
- Create a new user
- Log in as the new user
- Go to the new user's account page ("My account")
- Go to the Shortcuts tab
Currently, you see a set of radio buttons for the existing shortcut sets, and a text field named "Machine-readable name". This happens because there is no #access key on the id element like there is on the label element.
If you visit the form as an admin with the administer shortcuts permission, then only the label element is visible unless you want to customize the id. In which case you can choose to display the id element as you normally would by clicking the link next to the label element.
But in the case of a user without the administer shortcuts permission, you don't have access to the label element. The label element is then omitted from the form. Without it, the normal processes that hide the id don't work. So the id gets displayed to the user.
Proposed resolution
Copy the #access key from the label to the id so it is omitted entirely if the user should not have permission to see it.
Remaining tasks
User interface changes
The Machine-readable Name field will be removed from the form for people who shouldn't be able to see it.
Before:

After:

Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3389633
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:
- 3389633-shortcut-form-element-access
changes, plain diff MR !13637
Comments
Comment #2
brad.bulger commentedIt's such a small change, and has been like this for so long apparently, I feel like I must be missing something.
Comment #3
brad.bulger commentedComment #4
viren18febs commentedComment #5
smustgrave commentedThanks for reporting, next step would be to add a test showing the issue.
Comment #9
dcam commentedI disagree with the approach taken in #2. That would only hide the element visually. What we really need to do is set the
#accesson the element so it's removed from the form entirely for those who shouldn't have permission to see it. In fact, this is sort of a security gray-area. Users have the ability to see something that they shouldn't. Fortunately, they can't do anything with it. Entering text into the element does nothing. Otherwise I'd be contacting the security team. I considered adding the Security Improvements tag, but decided not to.I added test assertions in addition to changing the proposed fix. I also updated the issue summary.
Comment #10
dcam commentedComment #11
smustgrave commentedSo ran the test-only run
Based on the comment in the test I'd expect these to fail but they pass, doesn't fail till it gets to
So if we are still showing these items 1. Think we need screenshots so people can see the change. But comments should also be updated.
Comment #12
dcam commentedI'm happy to add screenshots so this issue is clearer. It's done.
No, they're passing correctly. There's no issue with those elements. In other words, they're being hidden appropriately. But there's no test coverage for it. I could have left those assertions out because they have nothing to do with this issue. But they were easy to add along with the assertion for this issue. Just consider it to be bonus coverage. See the before image I've added. There is no "New set" radio button or "Title" text field.
I assume you're talking about this comment:
Users without that permission shouldn't be able to see the "New set" radio, "Title" text field, or "Machine-readable Name" field. These are the elements related to adding a new shortcut set. Would you prefer alternative text that explains it in a different way?
Comment #13
smustgrave commentedSuppose this works. Shortcuts UI is so weird, probably why it's up to be removed too. But this does address the issue described in the summary.
Comment #14
jibranCan we have a test only PR to show the fail?
Comment #15
smustgrave commentedNo longer needed. In the MR there’s a test only run feature
Comment #16
jibranThanks for pointing that. RTBC++
Comment #17
longwaveI think this functionality is very rarely used which is why nobody has really noticed it before! Backported down to 10.6.x as an eligible bug fix.
Committed and pushed 508e5ebfd25 to main and ad20c0b53e7 to 11.x and b62d87bedd6 to 11.3.x and ec7d387dd4b to 10.6.x. Thanks!