Problem/Motivation
I have a Node Edit and Delete links on admin/content, the has permissions to edit/delete some nodes but not all of them.
Expected behavior:
Hidden Dropbutton for not accessible nodes.
Current behavior:
The previous Dropbutton is shown for not accessible nodes.
Steps to reproduce
Create two node types
Create sample content in each of the node types
Give user access to content overview
Edit content overview view to add a dropbutton field
Give user access to edit/delete one content type but not the other
Edit a node that the user has access to so it appears first in the admin page
Visit admin/content as that user
Rows that the user cannot edit get the dropbutton of the previous one they could edit.
Before

After

Proposed resolution
FieldPluginBase keeps state in $this->last_render_text and the Dropbutton uses the saved value. Therefor we should reset $this->last_render_text in renderText or advancedRender.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | 30-33-interdiff.txt | 446 bytes | acbramley |
| #33 | 2530634-33.patch | 10.46 KB | acbramley |
| #30 | 2530634-last-render-dropbutton.30.patch | 10.46 KB | lendude |
| #30 | interdiff-2530634-21-30.txt | 1.58 KB | lendude |
| #24 | dropbutton-after.png | 21.2 KB | lendude |
Comments
Comment #1
webflo commentedComment #2
dawehnerCome on, this is at least major
Comment #3
dawehner... I'm pretty convinced that this is the wrong fix. There is a usecase of using the token to itself in D7 for things like the mathfield. We maybe need to store the row index of the last rendered text, so we can compare that for the usecase of the dropbutton.
Comment #5
xjmThis sounds like a very similar bug to the one that would be caused in #2473873: Entity operations lack cacheability support, resulting in incorrect dropbuttons, but the fix sounds very different. Is it possible it's a duplicate?
Comment #6
xjmNW based on #3.
Comment #8
xjmSo let's say I have two nodes, node 3 and node 4. I can edit node 3 but only view node 4. Is the bug here that node 4 shows an edit dropbutton that links to node 3, even immediately after a full cache clear? Clear steps to reproduce and a test case would definitely help evaluate this issue.
Comment #9
acbramley commented@xjm that's what I'm experiencing, yes. The Edit link in views works properly, the operations dropdown doesn't (although the delete button is correctly suppressed).
Comment #10
larowlanAdded STR
Comment #11
larowlanComment #12
larowlanfailing test
Comment #13
larowlanAnd here's a fix that uses the 'We maybe need to store the row index of the last rendered text, so we can compare that for the usecase of the dropbutton' approach from #3
Comment #14
larowlanthe PHP_EOL can go in next pass, it was for easier debug, so this trim can go too
Comment #16
larowlanThis will mean it only works for the first row.. test and fix coming
Comment #18
larowlanThis is better
Comment #20
dawehnerAs said in IRC, "0" is a total valid rendered value in views.
Is this one needed as part of the patch?
Comment #21
larowlanFixes #20
Comment #22
lendudeIs there a good reason we can't keep this contained to Links/Dropbutton and not get FieldPluginBase involved at all? This passes the test locally, but maybe I'm missing some of the logic behind this.
Comment #23
dawehnerLess changes in base class are always better. I guess we want to apply some manual testing though?
Comment #24
lendudeMy thoughts exactly.
Manual testing with #22 works too. See screenshots. Also added screenshots to the IS.
Before
After
Comment #25
jibranAwesome! everyone seems happy here let's fix it then.
Comment #26
alexpott@Lendude but might not other plugins have the same problem and isn't the generic fix in #21 better?
Comment #27
lendude@alexpott If other plugins have this problem, then hmm maybe, but this is just happening because the dropdown plugin reuses generated values from other field plugins. That is not a pattern that is wide spread (to say the least), so if we can leave it of the base class and make the plugin that wants to do this work a little harder, that sounds acceptable to me.
If this wasn't possible without changes to the base class, sure, put it in, but making all field handlers in all Views track data that currently has one known use case (and there the same effect can be achieved without this data), sounds like data we can do without for now.
So, in short, I don't really see a use case here that warrants a generic fix over a specific fix. Feel free to disagree obviously :)
Comment #28
alexpottWell won't \Drupal\contextual\Plugin\views\field\ContextualLinks have the same problem? Also as \Drupal\views\Plugin\views\field\FieldPluginBase sets this value should it clear it?
Comment #29
lendude#2532200: Adding contextual links via Views fields does not work
\Drupal\contextual\Plugin\views\field\ContextualLinksThat thing is so broken, I have no idea if that would ever be bothered by this.Discussed this with @alexpott on IRC, this sounds like a better way to fix this, make FieldPluginBase clean up its own mess. Setting to NW for that.
So I think, moving this logic from #21 into FieldPluginBase instead of having it on Links.
Comment #30
lendudeSo something like this then.
Interdiff is against #21 for clarity.
Comment #31
thursday_bw commentedI came across this exact issue myself on my current project.
This patch looks clean, simple, and gets the job done.
Comment #32
alexpottI wonder about the difference between last_render_text and last_render...
Can be protected now - i think. Which is nice.
Comment #33
acbramley commentedFixed #32
Comment #34
dawehnerOne contains just the main output (last_render_text), and one contains the output after all the altering logic.
Comment #35
lendudeFeedback from #32 has been addressed, so back to RTBC.
Comment #36
alexpottCommitted and pushed 14afb77 to 8.3.x and c0a0e44 to 8.2.x. Thanks!
Unused use fixed on commit.