Updated: Comment #N

Problem/Motivation

When a user has access to use contextual links, but not to any operations that would appear in the contextual links dropdown, the pencil "expands" to show no menu, resulting in this graphical oddity:

empty_contextual_links.png

Steps to reproduce

  1. Install 8.x standard.
  2. Grant the authenticated user role permission to use contextual links.
  3. Create a test user.
  4. Log out and then log in as the test user.
  5. Hover over an item that has contextual links, e.g. the (also empty and pointlessly displayed) Tools menu, or the frontpage view.
  6. The contextual link pencil should appear. Click on it.

Proposed resolution

Do one of the following:

  1. Hide the contextual link icon when there are no operations available to the current user.
  2. Show the icon, but somehow indicate to the user that there are no options available, and fix the graphic.

Remaining tasks

(reviews needed, tests to be written or run, documentation to be written, etc.)

User interface changes

TBD

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Status: Active » Postponed (maintainer needs more info)

#2049601: Contextual links present an empty links trigger when no link items are available for an entity was marked as a duplicate of this issue.

There, it was also said that this can no longer be reproduced.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review
Issue tags: +JavaScript, +Spark, +sprint
FileSize
962 bytes

I can reproduce this using the same steps xjm provided in the issue summary, but instead of looking at the Tools menu, just look at the contextual link for the front page view.

This super simple patch fixes the problem :)

jessebeach’s picture

I was able to reproduce following xjm's STR. This is what the object of contextual links looks like for an authenticated person with contextual link permission, but no editing permissions:

And this is what the contextual links object looks like for an admin user:

In both cases, a list of ids of editable items is returned. In the case that a user does not have permission to any operation that would introduce a contextual link, the content of that item is returned as an empty string.

In this case, would it not be better to exclude the id from the returned list such that the returned result set would be an empty object for an authenticated user? Here's a patch that does this.

Wim Leers’s picture

Good catch! :)

Unfortunately, the answer is "no, we wouldn't want that". Once #2136507: Use client-side cache tags & caching to eliminate 1 HTTP requests/page for rendering Contextual Links lands, the rendered contextual links for each ID will actually be cached on the client-side. By returning the empty string, the client-side cache knows there's nothing there for the user. If we omit the result, then the client-side cache will have to talk to the server every time, over and over again.

jessebeach’s picture

Status: Needs review » Reviewed & tested by the community

Ah, yes, I knew you'd have a clever reason. Ok, given the need to support cacheing on the client side, the patch in #2 resolves this issue. I've manually tested and there are no behavior regressions.

I am RTBCing contextual_empty-2047671-2.patch (#2)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: 2047671-n-empty-contextuals.patch, failed testing.

Wim Leers’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
962 bytes

Re-uploading the #2 patch that jessebeach RTBC'd, to avoid any confusion.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, this seems to no longer apply.

Patch looks good though. Feel free to knock it back to RTBC when uploading.

Bojhan’s picture

Nice fix :)

nod_’s picture

Can we add the condition in the hasOwnProperty if? continue can be confusing.

jessebeach’s picture

Status: Needs work » Needs review
FileSize
915 bytes

Rerolled and I've taken nod_'s comment in #10 into account.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

All good, that works. Thanks.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Wim Leers’s picture

Issue tags: -sprint

Status: Fixed » Closed (fixed)

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