\Drupal\shortcut\Tests\ShortcutLinksTest::testShortcutBlockAccess()
Problem/Motivation
There is no contextual link to edit the list of shortcuts on the Shortcuts block.
Proposed resolution
Add a shortcut.contextual.yml to add a Edit shortcuts link.
Remaining tasks
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Instructions | ||
| Add automated tests | Instructions | ||
| Manually test the patch | Novice | Instructions | |
| Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
User interface changes
An added contextual link in the shortcut block. No new UI elements.
API changes
None.
Data model changes
None.
Original report by David_Rothstein
The shortcuts provided by the shortcut module can be displayed in the toolbar, but the module also provides a block. As originally pointed out by @jhodgdon at #647084: Missing shortcut edit and delete operations on shortcuts admin (but moved here since that issue has evolved into other things), the block does not have an "edit shortcuts" link in it like the toolbar does. It needs to.
Should be pretty straightforward to implement - the one complication I can see is that this is crying out to be done with contextual links. However, not all users have access to see contextual links, and if you have edit rights on the shortcut set but don't see the link on it, this could be a problem (unless we make sure that all classes of users have some other path to editing their shortcut set via the UI, they really need this link available on the block). So we might have to go with a basic text link in the body of the block for now.
| Comment | File | Size | Author |
|---|---|---|---|
| #94 | 717812-94.patch | 3.39 KB | smustgrave |
| #94 | interdiff-77-94.txt | 0 bytes | smustgrave |
Comments
Comment #1
jhodgdonWe need a quick patch for this. It should behave just like the current edit shortcuts link on the toolbar display of shortcuts.
Comment #2
mr.baileysQuick patch (basically a copy of the way the configure link is added to the toolbar).
Comment #3
jhodgdonThe link works for me. Do we need a second opinion here? I'm +1 for RTBC.
Comment #4
jhodgdon#2: 717812-shortcut-block-configure.patch queued for re-testing.
Comment #5
jhodgdonAssuming the patch still applies/passes... we've probably waited long enough for a second opinion?
Comment #6
tom_o_t commented#2: 717812-shortcut-block-configure.patch queued for re-testing.
Comment #7
webchickI'm not sure I agree with this. The navigation block doesn't have an "edit navigation" link just sitting around in it at the bottom, yet this is what this patch looks like:
Ick! ;)
What would be cool though is sticking the edit link in the contextual links like menu does.
(And though this adjusts something in t(), it doesn't add a new string so doesn't impact string freeze.)
Comment #8
jhodgdonDo we have to rehash this again?
The problem is that there is no other link to edit shortcuts, anywhere in the UI (or at least, there wasn't when I filed this issue), if you are using the block and not the Toolbar module. There has to be a link somewhere in the UI to get to the edit page. Doesn't there?
The Edit Shortcuts link is not contextual in the Toolbar either.
Sigh.
Comment #9
webchickI'm not sure why the observation that this breaks UX freeze warrants a "sigh". The toolbar is not a block, so sticking a link in the middle there is fine. But for blocks, the pattern we employ elsewhere for "edit this" is contextual links, not sticking an edit link in the block body.
However, it appears that there is a link to edit it now under admin/config/user-interface/shortcut/shortcut-set-1.
So is this "won't fix"?
Comment #10
jhodgdonOK.
Comment #11
David_Rothstein commentedIt's actually the page at admin/config/user-interface/shortcut that gives you a link to edit these. However, that requires "administer shortcuts" permission, which not everyone has. So there can still be people who have permission to edit shortcuts but no link in the UI to get there.
This is a bit of an edge case, though. And doing it as a contextual link would at least be better than not doing it at all.
However, the biggest problem with the screenshot in #7 is that the link is aligned left, which looks ugly. We already have a precedent of how to theme these links: theme_more_link(). The attached patch and screenshot show what that's like and that it's consistent with other blocks. The problem is that we'd like the text to say "Edit" rather than "More", but theme_more_links() isn't flexible enough to do that and it's too late to fix that, and building up a parallel theme function that did essentially the same thing would make themers mad, so we're stuck there. However, the "More" text isn't totally inaccurate either here (and we'd still get "edit shortcuts" showing up as hover text on the link), so I'm at least putting it up for discussion.
Comment #12
David_Rothstein commentedOh, and that was a cross-post, but we definitely shouldn't "won't fix" this.
In the worst case, we can still do the contextual link thing - which doesn't 100% solve the bug aspect of this, but at least comes closer, and has some advantages of its own anyway as @webchick said above.
Comment #13
webchickYeah... of the options contextual links is the only one that makes sense to me. Using a "More" link (while definitely nicer on the eyes) again breaks the UX because every other place we use it it's a list of those things, not an admin panel.
Comment #14
David_Rothstein commentedOK, here is a patch for that. As shown in the screenshot, the contextual links here now parallel the way the ones for menus work (including inheriting the usability problem where you have to click "list links" to edit them... yup).
Be warned also that this could be a bit of a performance hit for administrators who see this block. Because of the way the contextual links system works, it is going to try loading the shortcut set a few times per page to see if they have access to the various links. This could be mitigated by adding static caching to the shortcut_set_load() function.
Comment #15
jhodgdonI thought there was a UI in the user account editing space that gave you a link to edit your shortcuts too? I worked on a patch a while back that was supposed to do that... If that link exists, then this can actually be set to "won't fix".
The problem I see with this version of the patch is that
a) Not all themes display contextual links (Garland, for example, doesn't, at least last time I checked, which admittedly was months ago)
b) Not everyone has permission to see contextual links
The "edit shortcuts" link that is on the Toolbar display of shortcuts does not suffer from this limitation.
Comment #16
David_Rothstein commentedI don't think so - I believe there is only a link that goes in the other direction. Also, not all users who can edit shortcuts necessarily have permission to switch their own shortcut set, so they can't necessarily get to that user account page.
All themes do display contextual links (unless they go out of their way to hide them). However, it's definitely true that the Contextual Links module might not be enabled, or the user might not have permission to see them.
So that's why this isn't a 100% fix, but it's still much better than not doing anything to fix it at all, in my opinion.
However, we need to think about that caching issue, I guess.
Comment #17
David_Rothstein commentedComment #18
Bojhan commentedI am not sure, if its a really valid usecase - because it exists for many other modules that now have functionality exposed through contextual links.
Comment #19
jhodgdonWhen I filed the original issue on this, there was no way to get to the Edit Shortcuts page if you didn't use the toolbar (no contextual links existed). Has that changed? If not, by all means add the link using contextual links, but there should be a link somewhere, right?
Comment #20
Bojhan commentedOh, sorry my post was probably somewhat confusing - my argument was that supporting a usecase where there is neither access to the toolbar or contextual links, seemed a bit weird.
Comment #21
kscheirer#14: 717812-14-shortcut-block-configure.patch queued for re-testing.
Comment #25
tstoecklerComment #26
tstoecklerComment #27
autopoietic commentedComment #28
autopoietic commentedComment #31
mayurjadhav commentedComment #34
cybercraft2003 commentedWorking on this in the first timers contribution workshop.
Comment #35
cybercraft2003 commentedAnd now.. The patch
Comment #36
cybercraft2003 commentedComment #37
cybercraft2003 commentedMissing tests...
Comment #38
tstoecklerPatch and tests generally look good, thanks!
Marking needs work for the following points and also marking Novice to fix the review.
The type-hint should be
BlockPluginInterface.I think we should use
shortcut_current_displayed_set()instead ofshortcut_default_set()to match what the block is doing.There's a typo in the variable name: "shorcut" instead of "shortcut"
I don't think we need this check, the shortcut set will always have an ID.
Let's add a newline at the end.
I don't think this comment adds much value, let's just remove it.
Comment #39
cybercraft2003 commentedOk, i've made some modification.
Comment #40
tstoecklerWow @Cybercraft2003, I think you have nominated yourself for the coveted Fastest-Patch-of-the-Day award. ;-) Thanks a lot!
I found only some minor issue, but I hope it's OK to kick it back to you one more time. I promise it will be the last round ;-)
Let's remove the parameter documentation. Our documentation standard does not allow it unfortunately. (Yes, it looks nicer in PhpStorm that way, but we cannot have nice things ;-))
Instead of putting
$shortcut_idinto a separate variable let's just use['shortcut_set' => $shortcut_set->id()]directly.This should be "Checks" instead of "Check" (i.e. with a trailing "s".
"don't" should be "do not". Also this should not break into a new line. It should only break if it is longer than 80 characters.
Comment #41
cybercraft2003 commentedThe last from the car ;)
Comment #42
cybercraft2003 commentedComment #43
cybercraft2003 commentedComment #44
andypostbetter to call `\Drupal::currentUser()->isAuthenticated()`
should be removed
Comment #45
cybercraft2003 commentedOups... I will remove the var dump...
Comment #46
cybercraft2003 commentedOk, this my final patch (i hope).
The test condtion is more relevant with "hasPermission" method.
I remove the unnecessary test, fix code commentary, etc...
The previous patch has not the yml file... I've fixed that too.
EDIT : My patch created with phpstorm seems to not working... I will reupload new patch file. Sorry
Comment #48
cybercraft2003 commentedComment #49
cybercraft2003 commentedComment #51
lestat commentedIt's not possible to test this way contextual links. It should be requested from contextual.render.
We need to test it, like in Contextual module, I guess. Something like:
Don't know, what to do with
renderContextualLinks. Should we copy the function or re-use from Contextual module tests?Comment #52
cybercraft2003 commentedYep, the patch seems to work as designed but test crash the rebuild because it's not relevant.
I will try new test logic... It's my first contribution and I don't know how to drive unit test with the ddev container based quick sprint environment. I will try to execute phpunit test on my container based environment. Or if you know how to do that?
Comment #53
cybercraft2003 commentedI will try with this logic
Comment #54
cybercraft2003 commentedComment #56
cybercraft2003 commentedComment #58
MerryHamster commentedReroll #56 patch for 8.7.x
Comment #59
MerryHamster commentedComment #61
zahord commentedUpdating patch #58
Comment #62
zahord commentedComment #64
zahord commentedComment #65
zahord commentedComment #67
volkswagenchickTagging for upcoming contribution days.
Comment #68
johnpicozziUpdated the route name in shortcut.links.contextual.yml to use 'entity.shortcut_set.customize_form'. Feel like it makes more sense to go to the list link page instead of the edit set name.
Comment #69
johnpicozziUpdated patch to remove extra space causing issue in test.
Comment #70
johnpicozziLooks like the test is still failing, based on @LeStat comment above in #51 it might be a good idea to try re-using the contextual module tests instead of reinventing the wheel.
Comment #71
nginex commentedComment #72
mas2405 commentedQueued patch for retesting PHP 7.1 & MySQL 5.7
Comment #74
dksdev01 commentedI am working on recreating this patch for 8.8.x. thanks
Comment #75
dksdev01 commentedComment #76
cristiroma commentedI tested manually the functionality and it works.
However the patch was not working because it needed to be migrated to WebDriverTest since it relies on JavaScript actions. Also I moved the test inside the the shortcuts module.
Comment #77
cristiroma commentedAttaching a new patch which is addressing the coding style issues reported by the test bot.
Comment #78
volkswagenchicktagging for DrupalNorth 2019
Comment #79
rick hood commentedTested missing-shortcuts-link-717812-77.patch from #77 on local 8.8.x-dev and it worked fine. Added a shortcut link and saved, all good. At #D4DBoston
Comment #80
Christie Alcidor commentedComment #81
Christie Alcidor commentedComment #82
kscheirerBased on #79
Comment #83
larowlanshould we be adding #cache context here to indicate this varies by access now?
Comment #84
wim leers#83: Thanks for calling that out!
Woah… 😨
Even varying by
user.permissionsis not enough —shortcut_current_displayed_set()can even vary per user (usercache context)!This again goes back to #2339903: Shortcut module's access checking is insane, #2083123: Shortcut cleanup: Remove duplicated code and deprecate legacy functions and more. That's why this particular contextual links item needs this pretty crazy work-around.
IMHO we should stop building more on top of the excessive complexity of the Shortcut module and first simplify it, first make it sane. Only then can we truly make the UX better.
Comment #86
rithesh bk commentedcurrently i am working on it .....
Comment #87
rithesh bk commentedTested missing-shortcuts-link-717812-77.patch from #77 on local 8.9.x-dev and it worked fine. Added a shortcut link and saved, all good. Please find the attached screenshot ....
Comment #88
mradcliffeThank you for the screenshot, @Rithesh BK. It usually helps to also add this to the issue summary. At. this point, I think that the issue is still at work based on @larowlan's question and @Wim Leer's comment. We should leave the issue at Needs work.
I added the Needs issue summary update and removed the Novice tag because I'm not sure what the next step is based on that review. Should the issue be postponed on #2083123: Shortcut cleanup: Remove duplicated code and deprecate legacy functions?
Comment #94
smustgrave commentedrerolled for 9.5 but have not addressed #83 and #84. And based on #84 believe this should be postponed until https://www.drupal.org/project/drupal/issues/2083123 is committed
Comment #95
larowlanTriaged for bugsmash, this feels like a feature request to me
Comment #99
smustgrave commented