When a revision exists in a node and the user goes to the revisions tab and views the revision by clicking it's link the contextual links on the node show both the "quick edit" and "edit" options. This creates the odd behavior that, although the user is viewing the text of the revision, when they quick edit or edit the node the text changes to the text of the current version. Also when they click "delete" the delete screen for the node (not the revision) is shown.

Proposed solution

When the user is viewing a revision

  • Use "node_revision" as group for contextual links. This results in no longer adding the following three links
  • Remove "edit" from the contextual links so that the user does not think they can edit the revision without reverting
  • Remove "quick edit" from the contextual links so that the user does not think they can edit the revision in place without reverting
  • Remove "delete" from the contextual links so that the user will not delete a node thinking they are deleting the revision

Tested in chrome on mac yosemite

CommentFileSizeAuthor
#115 interdiff-2362435-108-115.txt615 bytesmarkdorison
#115 when_viewing_a-2362435-115.patch5.54 KBmarkdorison
#110 empty_list.png36.2 KBxjm
#108 interdiff.txt3.2 KBamateescu
#108 2362435-108.patch5.57 KBamateescu
#106 interdiff-2362435-102-106.txt558 bytesmarkdorison
#106 when_viewing_a-2362435-106.patch5.74 KBmarkdorison
#102 interdiff-2362435-100-102.txt603 bytesmarkdorison
#102 when_viewing_a-2362435-102.patch5.75 KBmarkdorison
#100 when_viewing_a-2362435-100.patch5.75 KBdeepakaryan1988
#97 when_viewing_a-2362435-97.patch5.58 KBmartin107
#97 interdiff-2362435-95-97.txt657 bytesmartin107
#95 interdiff-2362435-87-95.txt3.48 KBmarkdorison
#95 when_viewing_a-2362435-95.patch5.58 KBmarkdorison
#88 Screen Shot 2016-05-31 at 5.39.25 PM.png17.73 KBadamzimmermann
#87 when_viewing_a-2362435-87-interdiff.txt625 bytesmarkdorison
#87 when_viewing_a-2362435-87.patch5.55 KBmarkdorison
#84 when_viewing_a-2362435-84.patch5.49 KBhampercm
#77 2362435-77.patch5.5 KBlokapujya
#77 2362435-77-interdiff.txt994 byteslokapujya
#75 2362435-75-interdiff.txt3.23 KBlokapujya
#75 2362435-75.patch5.5 KBlokapujya
#68 when_viewing_a-2362435-68.patch5.49 KBtimmillwood
#67 TEST-ONLY-67.patch4.4 KBgoogletorp
#65 interdiff-2362435-58-65.txt408 bytesdeepakaryan1988
#65 when_viewing_a-2362435-65.patch5.56 KBdeepakaryan1988
#58 interdiff.txt1.54 KBwim leers
#58 when_viewing_a-2362435-58.patch5.76 KBwim leers
#55 Screen-Shot-After-2362435-53.png43 KBkerby70
#54 Screen-Shot-After-2362435-53.png.png43 KBkerby70
#54 Screen-Shot-Before-2362435-0.png52.14 KBkerby70
#53 interdiff.txt673 bytesalvar0hurtad0
#53 when_viewing_a-2362435-53.patch6.51 KBalvar0hurtad0
#48 interdiff-2362435-44-48.txt1.24 KBhampercm
#48 when_viewing_a-2362435-48.patch6.56 KBhampercm
#44 when_viewing_a-2362435-44.patch5.56 KBtadityar
#40 when_viewing_a-2362435-40-test_only-do-not-test.patch4.4 KBhampercm
#40 when_viewing_a-2362435-40.patch5.56 KBhampercm
#39 when_viewing_a-2362435-39.patch4.87 KBhampercm
#39 when_viewing_a-2362435-39-tests_only-do-not-test.patch4.05 KBhampercm
#27 when_viewing_a-2362435-19-reuploaded.patch839 byteswim leers
#23 contextual_links_revisions-2362435-23.patch2.83 KBsdelbosc
#19 when_viewing_a-2362435-19.patch839 bytesAlienpruts
#16 when_viewing_a-2362435-16.patch1.06 KBAlienpruts
#16 interdiff-2362435-#12.txt968 bytesAlienpruts
#12 when_viewing_a-2362435-12.patch1.17 KBAlienpruts
#11 add_methods_for-2325517-51.patch4.3 KBAlienpruts
#11 interdiff-8.txt928 bytesAlienpruts
#8 2362435-7.patch1.17 KBPalashvijay4O
#4 when_viewing_a-2362435-4.patch997 bytesnlisgo

Comments

tkoleary’s picture

Priority: Major » Normal
wim leers’s picture

Title: When viewing a revision quick edit and edit are enabled » When viewing a revision, the Quick Edit and Edit operations are available, but revisions can only be Reverted or Deleted
Component: quickedit.module » contextual.module
Priority: Normal » Major
Issue tags: +Usability, +Novice, +php-novice

Great catch!

nlisgo’s picture

The proposed behaviour would be consistent with the behaviour in Drupal 7.

nlisgo’s picture

Status: Needs work » Needs review
StatusFileSize
new997 bytes

This patch addresses the removal of the Edit and Quick Edit links.

Status: Needs review » Needs work

The last submitted patch, 4: when_viewing_a-2362435-4.patch, failed testing.

wim leers’s picture

I think you want to use isDefaultRevision().

tim.plunkett’s picture

Issue tags: +Needs tests
Palashvijay4O’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.17 KB

A test patch .

Status: Needs review » Needs work

The last submitted patch, 8: 2362435-7.patch, failed testing.

Alienpruts’s picture

Assigned: Unassigned » Alienpruts
Issue tags: +DrupalCamp Ghent 2014
Alienpruts’s picture

Assigned: Alienpruts » Unassigned
Status: Needs work » Needs review
StatusFileSize
new928 bytes
new4.3 KB

Failed testing because of missing ;

Tested code, looks good. However, no contextual links are shown at all. Is this an acceptable solution?

Alienpruts’s picture

StatusFileSize
new1.17 KB

Goofed up, here is the correct patch.

That will teach me to work on two issues at the same time :)

Status: Needs review » Needs work

The last submitted patch, 12: when_viewing_a-2362435-12.patch, failed testing.

wim leers’s picture

+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -169,7 +170,8 @@ protected static function buildLinks(NodeInterface $entity, $view_mode) {
+    $revision = entity_load($entity->getEntityTypeId(),$entity->id());
+    if ($entity->id() && ContentEntityBase::isDefaultRevision($revision)==TRUE) {

I think my request to use isDefaultRevision() confused you a bit :)

We already have an $entity object. Since this is NodeViewBuilder (which is responsible for building a render array to view a node), we now that we're dealing with Node entities.

In the code for Node you see this:

class Node extends ContentEntityBase implements NodeInterface

which leads us to NodeInterface, in whose code you see this:

interface NodeInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface

And this then leads us to ContentEntityInterface, whose code looks like this:

RevisionableInterface

Conclusion: all Node entities are guaranteed to implement RevisionableInterface.

It is RevisionableInterface that requires isDefaultRevision() to be implemented. Hence that method is available directly on all objects that implement RevisionableInterface, of which the Node class is one, and hence all Node entity objects also have it.

In other words, the $revision = entity_load(…) is unnecessary; $entity already is of a certain revision.

And calling on ContentEntityBase::isDefaultRevision() is definitely wrong: you can only call methods like that if they're static. Static methods are bound to the class, not objects (instances of the class), and hence cannot access $this.
It's much, much simpler, actually :) You can simply call $entity->isDefaultRevision() — that's it! :)

Alienpruts’s picture

Assigned: Unassigned » Alienpruts

Tnx Wim,

wow, didn't thought this far. I have some good OOP knowledge, but it escaped my mind to go look for this specific method.

Will patch this.

In retrospect, do you have any tips for me for 'remembering' to check all methods an object has access to? I think I was misled because my IDE didn't have isDefaultRevision() as an autocomplete, so I did not remember to check all interfaces. Do you know of a technique or something so you can check this?

Tnx,

Alienpruts’s picture

Assigned: Alienpruts » Unassigned
Status: Needs work » Needs review
StatusFileSize
new968 bytes
new1.06 KB

Patched previous patch, tnx to Wim Leers #14

wim leers’s picture

Status: Needs review » Needs work

In retrospect, do you have any tips for me for 'remembering' to check all methods an object has access to? I think I was misled because my IDE didn't have isDefaultRevision() as an autocomplete, so I did not remember to check all interfaces. Do you know of a technique or something so you can check this?

To ensure that an IDE *can* correctly autocomplete, we add /** @var \namespace\interface $variable_name comments in the code. This is necessary when typehints are set to a generic interface (like EntityInterface), which allows implementations of that interface to be passed in… but an implementation is not limited to a single interface, and therefore doesn't know if e.g. RevisionableInterface is also implemented.

That's the general explanation. Hence the general advice would be: look whether the object you're receiving implements additional interfaces.

However, in this case, such a comment does exist! So it looks like your IDE is kind of broken, because that comment does exist and does have the expected effect for me: $entity->is autocompletes to isDefaultRevision().
Not sure what's wrong in your IDE.


Manually tested the patch. Works correctly :)

Unfortunately, there is one small problem in the patch preventing me from RTBC'ing this. Please fix it and then this is RTBC :)

+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -10,6 +10,7 @@
+use Drupal\Core\Entity\ContentEntityBase;

This use statement is no longer necessary.

Alienpruts’s picture

Assigned: Unassigned » Alienpruts

Tnx Wim Leers, indeed strange that the IDE (Netbeans in this case) is not able to 'autocomplete' these methods. Not that I'm so dependant on that feature, but it is nice just to be able to look at all the methods on any given object. I've noticed some other oddities with Netbeans lately, so I'm going to take a look under the hood, so to speak.

Your patch is coming up :)

Alienpruts’s picture

Assigned: Alienpruts » Unassigned
Status: Needs work » Needs review
StatusFileSize
new839 bytes

Here you go.

Took a bit longer than expected : had to reroll the patch.

One conflict (duh) : the use line was removed for the patch to be able to be applied.

Hope all is wel from here on :)

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Perfect, thanks!

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

$entity->isDefaultRevision() can return TRUE even though $entity->id() will return FALSE. So it seems wrong to remove the $entity->id() check. I might be missing something...

wim leers’s picture

#21: I thought the same: I thought that ->id() would still be necessary. To prevent contextual links from showing up in previews, right? Turns out contextual links already show up in previews in HEAD. This diff doesn't affect that. To fix that, we need to check for $node->in_preview, but that's out of scope.
That's what we get for ever using if ($entity->id()) {…} in the first place: it makes very little sense…

sdelbosc’s picture

StatusFileSize
new2.83 KB

Here is a patch for the entire proposed solution.
Note that though I have not seen any case where id() returns FALSE I have kept the test.

sdelbosc’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: contextual_links_revisions-2362435-23.patch, failed testing.

wim leers’s picture

@sdelbosc: is it possible that you're using an amazingly ancient version of Drupal 8? "Quick Edit" module was still called "Edit" in your patch, which happened more than half a year ago, in April: https://www.drupal.org/node/2242711.

Could you reroll against the latest Drupal 8, or shall I do that for you?

wim leers’s picture

Assigned: Unassigned » tstoeckler
StatusFileSize
new839 bytes

Oh, and wait, you're proposing to add "Revert to revision" and "Delete revision" contextual links! That's fine, but that belongs in a new issue. This means that comments #23—#26 should be ignored.

Reuploading #19 which IMHO is still RTBC worthy. Pinging tstoeckler for feedback.

sdelbosc’s picture

Yes, I used 8.x branch and realised the mistake when my patch failed testing.

Regarding the Revert to revision and Delete revision links, I think we should update the description of the issue as it is confusing.
Otherwise, from what I have seen the patch from #19 is fine for me in the sense that I have not found any use case where id() is FALSE (on 8.x branch at least).

By the way, if you could confirm that 8.0.x is the branch I should use it would be great.

wim leers’s picture

Title: When viewing a revision, the Quick Edit and Edit operations are available, but revisions can only be Reverted or Deleted » When viewing a revision, the Quick Edit and Edit operations are available, but should not be: revisions may only be Reverted or Deleted
Status: Needs work » Needs review

Yes, I used 8.x branch and realised the mistake when my patch failed testing.

Aha, heh :)

Regarding the Revert to revision and Delete revision links, I think we should update the description of the issue as it is confusing.

Clarified the title.

By the way, if you could confirm that 8.0.x is the branch I should use it would be great.

Yes, 8.0.x is the one you want. And just to make sure: please do open a new issue for what you want to do :)

sdelbosc’s picture

Do you know the issue number of the other issue you are talking about?
The one supposed to show Revert and Delete contextual links on revisions.

wim leers’s picture

@sdelbosc: there isn't one, please create one :)

sdelbosc’s picture

Sorry misunderstanding on my side. However, when reading the proposed solution in the description of this ticket, it seems to me that adding these 2 links is part of this ticket and not a new one.

wim leers’s picture

#32: it's not. I already clarified the title in #29.

jibran’s picture

Issue tags: +Need tests

Can we add some quick test for this?

jibran’s picture

Issue tags: -Need tests +Needs tests

sorry added wrong tag.

sdelbosc’s picture

For info. I have created [2389341] according to the previous comments.
@Wim, would be great if you could check that this is what you expected.

tstoeckler’s picture

Assigned: tstoeckler » Unassigned
Status: Needs review » Needs work

It still seems strange to me to remove the id() check. Even if it's incorrect, IMO we should fix that in a separate issue including dedicated tests for that.

In any case marking needs work due to the "Needs tests" tag.

hampercm’s picture

Assigned: Unassigned » hampercm

Writing tests for this issue...

hampercm’s picture

Assigned: hampercm » Unassigned
Issue summary: View changes
Issue tags: -Needs tests
StatusFileSize
new4.05 KB
new4.87 KB

Here is what I have so far for the tests. I added the new test code to an existing function in NodeRevisionsTest.php, as that seemed to be the most relevant existing test class. This allowed me to take advantage of some existing test set-up functionality in that class.

In the process of creating these tests, however, I found that I had some concerns with the patch from #27:

1) I agree with @tstoeckler that the if( $entity->id() ) check should be left in. I see no justification for removing it. It seems quite likely that removing it will create problems elsewhere.

2) If I'm understanding things correctly, the patch in #27 removes the quickedit, edit, and delete contextual links when viewing revisions by completely disabling the creation of the contextual links "popup menu". This will create problems if other contextual links need to be displayed when viewing a revision, and thus seems like a poor solution.

Interestingly, the patch from the related issue #2389341 removes the quickedit, edit, and delete contextual links (in addition to adding new links for reverting and deleting revisions). My brain is pretty fried at this point, so it's not clear to me exactly how it accomplishes that, but perhaps that patch can be adapted to be a solution for this issue?

hampercm’s picture

Status: Needs work » Needs review
StatusFileSize
new5.56 KB
new4.4 KB

Here is an alternative patch for this issue, derived from the patch by @sdelbosc in related issue #2389341. Instead of completely disabling contextual links for revisions, this patch fixes the issue by giving revisions their own separate contextual links, which are currently empty.

I also updated my test code to account for the return of the contextual links menu for revisions.

Status: Needs review » Needs work

The last submitted patch, 40: when_viewing_a-2362435-40.patch, failed testing.

The last submitted patch, 40: when_viewing_a-2362435-40.patch, failed testing.

tadityar’s picture

Status: Needs work » Needs review
StatusFileSize
new5.56 KB

Re-rolled

Status: Needs review » Needs work

The last submitted patch, 44: when_viewing_a-2362435-44.patch, failed testing.

tadityar’s picture

Version: 8.0.0-beta2 » 8.0.x-dev
Status: Needs work » Needs review

Isn't this supposed to be tested against 8.0.x-dev? Or was it correct to test it against 8.0.0-beta2? Please correct me if I'm wrong.

hampercm’s picture

StatusFileSize
new6.56 KB
new1.24 KB

After further examination, I realized that I needed to include a bit more of @sdelbosc's patch in order to prevent the "Quick Edit" link from appearing under certain circumstances. Sorry for the confusion on this.

gippy’s picture

I applied when_viewing_a-2362435-48.patch using a clean install of D8 and the patch correctly removed all three contextual links when displaying the older revision. Tested with Yosemite and Chrome.

gippy’s picture

Status: Needs review » Reviewed & tested by the community
wim leers’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -183,6 +183,9 @@
+          'metadata' => array(
+            'quickEdit' => '0'
+          ),

+++ b/core/modules/quickedit/js/quickedit.js
@@ -514,6 +514,13 @@
+        // Check if quick edit feature is explicitly disabled.
+        var dataContextualId = $links.closest('.contextual-region').find('[data-contextual-id]').attr('data-contextual-id');
+        if (dataContextualId.indexOf('quickEdit=0') > -1) {
+          return false;
+        }

I don't understand why this is necessary. It feels very hacky. Can you please explain it?

hampercm’s picture

In response to #51, this code's purpose is to explicitly disable the addition of a "Quick Edit" contextual link. Without this code, the quick edit link will be incorrectly added to the context menu for node revisions in the case where there are other contextual links (for example, those proposed to be added by #2389341: When viewing a revision the Reverted or Deleted links should be available in contextual links). There might be other ways of doing the same thing that would feel less hack-ish. I'm certainly open to ideas.

I originally adapted this code from @sdelbosc's patch for that issue (as mentioned in #40) because it seemed to be a good solution to this issue, without breaking contextual links entirely for revisions.

Looking at the code again, the JS code could be cleaned up quite a bit, to something more like:

        // Check if quick edit feature is explicitly disabled.
        var dataContextualId = $(contextualLink.el).attr('data-contextual-id');
        if (dataContextualId.indexOf('quickEdit=0') > -1) {
          return true;
        }
alvar0hurtad0’s picture

Status: Needs work » Needs review
StatusFileSize
new6.51 KB
new673 bytes

Let me help, this is the patch on #48 with #52 fix.

kerby70’s picture

#53 removes the 3 links and test passed.

Screen shot before on revision page:
Before patch on content revision page - show edit pencil when clicked has Quick edit, Edit, and Delete links.

Screen shot after on revision page:
After patch on content revision page - shows edit pencil when clicked has no contextual links.

kerby70’s picture

StatusFileSize
new43 KB
kerby70’s picture

Status: Needs review » Reviewed & tested by the community
wim leers’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/node/src/NodeViewBuilder.php
    @@ -171,10 +171,23 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView
    +          'route_parameters' => array('node' => $entity->id()),
    +          'metadata' => array('changed' => $entity->getChangedTime()),
    ...
    +          'route_parameters' => array(
    +            'node' => $entity->id(),
    +            'node_revision' => $entity->getRevisionId(),
    +          ),
    +          'metadata' => array(
    +            'quickEdit' => '0'
    +          ),
    

    These aren't formatted consistently.

  2. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -19,6 +20,13 @@ class NodeRevisionsTest extends NodeTestBase {
    +  public static $modules = array('node', 'datetime', 'contextual');
    

    Just "contextual" would be sufficient, the parent class' modules are also enabled automatically (IIRC).

  3. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -93,6 +102,18 @@ function testRevisions() {
    +    $this->assertTrue(strstr($json[$ids[0]], '<li class="entitynodeedit-form"><a href="' . base_path() . 'node/' . $node->id() . '/edit">Edit</a></li>'),
    +      'The "Edit" contextual link is shown for the default revision.');
    +    $this->assertTrue(strstr($json[$ids[0]], '<li class="entitynodedelete-form"><a href="' . base_path() . 'node/' . $node->id() . '/delete">Delete</a></li>'),
    +      'The "Delete" contextual link is shown for the default revision.');
    
    @@ -106,6 +127,18 @@ function testRevisions() {
    +    $this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodeedit-form">'),
    +      'The "Edit" contextual link is not shown for a non-default revision.');
    +    $this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodedelete-form">'),
    +      'The "Delete" contextual link is not shown for a non-default revision.');
    

    We put the assertion messages on the same line.

  4. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -203,4 +236,23 @@ function testNodeRevisionWithoutLogMessage() {
    +  }
     }
    

    Nit: newline after the last method.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new5.76 KB
new1.54 KB

Also, still not convinced by this approach — sorry.

+++ b/core/modules/quickedit/js/quickedit.js
@@ -514,6 +514,13 @@
+        // Check if quick edit feature is explicitly disabled.
+        var dataContextualId = $(contextualLink.el).attr('data-contextual-id');
+        if (dataContextualId.indexOf('quickEdit=0') > -1) {
+          return false;
+        }

This is too late in the process.

Also, why do we even need quickEdit=0? Zero contextual links are defined on that route! AFAICT this also works, and is much, much simpler.

disasm’s picture

Lets get the screenshots added to the issue summary above.

sher1’s picture

Issue tags: +Needs reroll

I am at DrupalCon LA. This patch no longer applies. It will need to be re-rolled. I will review the patch and see if I can re-roll it.

sher1’s picture

re-saved comment

sher1’s picture

I can't see how I would re-roll it, (newbie issues).

wim leers’s picture

Status: Needs review » Needs work

If this needs a reroll, it needs to be marked as "needs work".

deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.56 KB
new408 bytes

@Wim @sher1 I have re-rolled #58 . Please check it.
Attaching interdiff also.

martin107’s picture

Issue tags: -Needs reroll
googletorp’s picture

StatusFileSize
new4.4 KB

Testing the patch alone, to see if it fails as expected.

timmillwood’s picture

StatusFileSize
new5.49 KB

Re-rolled the patch

legolasbo’s picture

Status: Needs review » Needs work

Only a review of the code, I haven't looked at the functionality.

  1. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -110,6 +112,18 @@ function testRevisions() {
    +    $ids = array('node:node=' . $node->id() . ':changed=' . $node->getChangedTime());
    +    $response = $this->renderContextualLinks($ids, "node/" . $node->id());
    
    @@ -123,6 +137,18 @@ function testRevisions() {
    +    $ids = array('node_revision::node=' . $node->id() . '&node_revision=' . $node->getRevisionId() . ':');
    +    $response = $this->renderContextualLinks($ids, "node/" . $node->id() . '/revisions/' . $node->getRevisionId() . '/view');
    
    @@ -222,6 +248,25 @@ function testNodeRevisionWithoutLogMessage() {
    +  protected function renderContextualLinks($ids, $current_path) {
    

    renderContextualLinks could just take the node as an argument to reduce code duplication.

  2. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -110,6 +112,18 @@ function testRevisions() {
    +    $json = Json::decode($response);
    
    @@ -123,6 +137,18 @@ function testRevisions() {
    +    $json = Json::decode($response);
    
    @@ -222,6 +248,25 @@ function testNodeRevisionWithoutLogMessage() {
    +    return $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => $current_path)));
    

    Instead of returning the raw response, renderContextualLinks could return the json object to reduce code duplication.

  3. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -110,6 +112,18 @@ function testRevisions() {
    +    $this->assertTrue(strstr($json[$ids[0]], '<li class="entitynodeedit-form"><a href="' . base_path() . 'node/' . $node->id() . '/edit">Edit</a></li>'),
    +      'The "Edit" contextual link is shown for the default revision.');
    +    $this->assertTrue(strstr($json[$ids[0]], '<li class="entitynodedelete-form"><a href="' . base_path() . 'node/' . $node->id() . '/delete">Delete</a></li>'),
    +      'The "Delete" contextual link is shown for the default revision.');
    
    @@ -123,6 +137,18 @@ function testRevisions() {
    +    $this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodeedit-form">'),
    +      'The "Edit" contextual link is not shown for a non-default revision.');
    +    $this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodedelete-form">'),
    +      'The "Delete" contextual link is not shown for a non-default revision.');
    

    These should be on one line, not two.

DickJohnson’s picture

Assigned: Unassigned » DickJohnson

Assigning to myself, working for this on DrupalCon Barcelona.

dawehner’s picture

+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -153,10 +153,20 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView
+      if ($entity->isDefaultRevision()) {
+        $build['#contextual_links']['node'] = array(
+          'route_parameters' => array('node' => $entity->id()),
+          'metadata' => array('changed' => $entity->getChangedTime()),
+        );
+      }
+      else {
+        $build['#contextual_links']['node_revision'] = array(
+          'route_parameters' => array(
+            'node' => $entity->id(),
+            'node_revision' => $entity->getRevisionId(),
+          ),
+        );
+      }
     }

Added a PR for entity module to generalize that bit: https://github.com/fago/entity/pull/23

wim leers’s picture

<3

Crell’s picture

We ran into a closely related issue with Workbench Moderation a while back. Our solution was here: #2635890: Quick Edit integration. Basically, we disable quick edit entirely when showing any revision other than the latest revision, as doing otherwise leads to unexpected branching and unmanaged weirdness. Dropping a link here for context.

wim leers’s picture

Title: When viewing a revision, the Quick Edit and Edit operations are available, but should not be: revisions may only be Reverted or Deleted » When viewing a revision, the Quick Edit and Edit contextual link operations are available, but should not be: revisions may only be Reverted or Deleted
lokapujya’s picture

Assigned: DickJohnson » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.5 KB
new3.23 KB

#69
1.) Yes, but the input varies: "node:node=" vs . "node_revision::node="
2, 3.) done.

Status: Needs review » Needs work

The last submitted patch, 75: 2362435-75.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new994 bytes
new5.5 KB

remove leftover parenthesis.

samiullah’s picture

Assigned: Unassigned » samiullah
samiullah’s picture

@lokapujya, I am able to reproduce the issue. For the revision when click on contextual menu, Drop down is not reflecting.

samiullah’s picture

Status: Needs review » Needs work
lokapujya’s picture

Hmm, I guess this never worked completely as shown by the missing "Delete" in the screenshots in comment #54.

lokapujya’s picture

Can anyone confirm that the delete link should show up. At least, the contextual links probably shouldn't be empty like they do in the #54 screenshot, right?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hampercm’s picture

Title: When viewing a revision, the Quick Edit and Edit contextual link operations are available, but should not be: revisions may only be Reverted or Deleted » When viewing a revision, the Quick Edit, Edit, and Delete contextual link operations are available, but should not be, as they only affect the default revision
Assigned: samiullah » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
StatusFileSize
new5.49 KB

Rerolled patch from #77.

@lokapujya, the Delete link should not be showing up, as it will delete the entire node rather than the revision that is being viewed. This would most likely be unexpected behavior for users. #2389341: When viewing a revision the Reverted or Deleted links should be available in contextual links is intended to add back a "Delete revision" contextual link.

I've changed the title to match the intent of this issue.

hampercm’s picture

Title: When viewing a revision, the Quick Edit, Edit, and Delete contextual link operations are available, but should not be, as they only affect the default revision » When viewing a revision, the Quick Edit, Edit, and Delete contextual link operations are available, but should not be
lokapujya’s picture

Issue tags: -DrupalCamp Ghent 2014

The contextual links are still empty though. What should happen in this case?

markdorison’s picture

  • Resolved PHPCS warning in NodeRevisionsTest RE: $modules array declaration: "If the line declaring an array spans longer than 80 characters, each element should be broken into its own line."
  • No functional changes.
  • Patch worked as expected.
adamzimmermann’s picture

Issue summary: View changes
StatusFileSize
new17.73 KB

The links are hidden for me as intended, but as #86 noted, it now has the odd empty contextual links behavior.

empty contextual links

adamzimmermann’s picture

Issue summary: View changes
hampercm’s picture

The empty contextual links is the result of a separate Drupal Core bug: #2650910: Contextual links button is always rendered even when no links are available (with warm client-side cache) Once that is fixed, the empty contextual links visible in #88 will go away.

alexpott’s picture

Priority: Major » Critical

Discussed with @catch, @xjm, @dixon, @amateescu, @berdir, @effulgentsia, @timmillwood - we decided to promote this to critical as the user is not editing what they think they are editing when quick editing a revision - this could result in data lose and is certainly unexpected and confusing.

wim leers’s picture

  1. +++ b/core/modules/node/src/NodeViewBuilder.php
    @@ -146,10 +146,20 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView
    +      if ($entity->isDefaultRevision()) {
    +        $build['#contextual_links']['node'] = array(
    +          'route_parameters' => array('node' => $entity->id()),
    +          'metadata' => array('changed' => $entity->getChangedTime()),
    +        );
    +      }
    +      else {
    +        $build['#contextual_links']['node_revision'] = array(
    +          'route_parameters' => array(
    +            'node' => $entity->id(),
    +            'node_revision' => $entity->getRevisionId(),
    +          ),
    +        );
    +      }
    

    The first case has changed in its metadata, the revision one should too, because revisions can also be edited without creating a new revision.

  2. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -165,6 +184,17 @@ function testRevisions() {
    +    $this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodeedit-form">'),
    +      'The "Edit" contextual link is not shown for a non-default revision.');
    +    $this->assertFalse(strstr($json[$ids[0]], '<li class="entitynodedelete-form">'),
    +      'The "Delete" contextual link is not shown for a non-default revision.');
    

    Nit: strange wrapping here.

  3. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -318,6 +348,27 @@ function testNodeRevisionWithoutLogMessage() {
    +   * @param array $ids
    

    Nit: string[]

  4. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -318,6 +348,27 @@ function testNodeRevisionWithoutLogMessage() {
    +   *   An array of contextual link ids.
    

    Nit: s/ids/IDs/

  5. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -318,6 +348,27 @@ function testNodeRevisionWithoutLogMessage() {
    +   *   The decoded Json response body.
    

    Nit: s/Json/JSON/

  6. +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
    @@ -318,6 +348,27 @@ function testNodeRevisionWithoutLogMessage() {
    +    $post = array();
    ...
    +    $response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => $current_path)));
    

    Nit: s/array()/[]/

hampercm’s picture

Assigned: Unassigned » hampercm

Making changes from review in #93...

markdorison’s picture

Assigned: hampercm » Unassigned
StatusFileSize
new5.58 KB
new3.48 KB

Suggestions from #93 implemented as well as some additional array syntax changes for new code. Patch and interdiff attached.

wim leers’s picture

I'm afraid #95 introduced a new array syntax case:

+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -147,18 +147,19 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView
+          'metadata' => array('changed' => $entity->getChangedTime()),

s/array()/[]/

martin107’s picture

StatusFileSize
new657 bytes
new5.58 KB

a little fix.

Status: Needs review » Needs work

The last submitted patch, 97: when_viewing_a-2362435-97.patch, failed testing.

deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new5.75 KB

Rerolled it.

Status: Needs review » Needs work

The last submitted patch, 100: when_viewing_a-2362435-100.patch, failed testing.

markdorison’s picture

Status: Needs work » Needs review
StatusFileSize
new5.75 KB
new603 bytes
+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -146,10 +146,21 @@ protected function alterBuild(array &$build, EntityInterface $entity, EntityView
+          'metadata' => array('changed' => $entity->getChangedTime()),

Updated array syntax.

Status: Needs review » Needs work

The last submitted patch, 102: when_viewing_a-2362435-102.patch, failed testing.

xjm’s picture

xjm’s picture

This issue is also critical for phase A of the Workflow Initiative.

markdorison’s picture

Status: Needs work » Needs review
StatusFileSize
new5.74 KB
new558 bytes

Updated remaining array syntax. I am having trouble parsing the failing test results.

xjm’s picture

The most recent test failure was caused by #2749955: Random fails in UpdatePathTestBase tests so not the result of this patch.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new5.57 KB
new3.2 KB

There were a few code style issues left, otherwise this patch looks ready to me.

wim leers’s picture

RTBC++

xjm’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
StatusFileSize
new36.2 KB
+++ b/core/modules/node/src/Tests/NodeRevisionsTest.php
@@ -34,7 +35,13 @@ class NodeRevisionsTest extends NodeTestBase {
-  public static $modules = array('node', 'datetime', 'language', 'content_translation');
+  public static $modules = [
+    'node',
+    'contextual',
+    'datetime',
+    'language',
+    'content_translation',
+  ];

In general I prefer that we not reformat arrays like this when changing lines for other reasons, because it makes word diffs unusable. Not going to block a critical on that, though. ;)

I tested this patch manually and confirmed there are no more dangerous edit/delete links on past revisions! Yay!

However, it introduces a different bug. With the patch, the contextual links "friendly pencil" is displayed, but expands to an empty dropdown:

That's a better bug to have, but it is still a bug I think.

markdorison’s picture

However, it introduces a different bug. With the patch, the contextual links "friendly pencil" is displayed, but expands to an empty dropdown:

@xjm The issue you are describing is being handled in #2650910: Contextual links button is always rendered even when no links are available (with warm client-side cache).

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC per #111.

The last submitted patch, 39: when_viewing_a-2362435-39-tests_only-do-not-test.patch, failed testing.

The last submitted patch, 40: when_viewing_a-2362435-40-test_only-do-not-test.patch, failed testing.

markdorison’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.54 KB
new615 bytes

Attached patch undos reformatting of $modules array as requested by @xjm in #110.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks @markdorison :)

alexpott’s picture

I guess the question now is should #2650910: Contextual links button is always rendered even when no links are available (with warm client-side cache) block this. I don't think so but it'd be good to get more opinions on this.

wim leers’s picture

dawehner’s picture

Issue summary: View changes

tried to understand the patch and updated the change record for that. I hope that makes a bit more sense to more than just me.

xjm’s picture

Aha! Thanks for the issue link.

I think that that bug is less bad than this bug, so I do not think it should block this issue. That bug is a "huh wtf?" but this one is a "huh wtf and lol I deleted my node". :)

  • xjm committed 4668a26 on 8.2.x
    Issue #2362435 by hampercm, markdorison, Alienpruts, lokapujya, Wim...

  • xjm committed 16e228d on 8.1.x
    Issue #2362435 by hampercm, markdorison, Alienpruts, lokapujya, Wim...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed 4668a26 and pushed to 8.2.x and 8.1.x. Thanks!

wim leers’s picture

#120 Nice summary :D

  • xjm committed 4668a26 on 8.3.x
    Issue #2362435 by hampercm, markdorison, Alienpruts, lokapujya, Wim...

  • xjm committed 4668a26 on 8.3.x
    Issue #2362435 by hampercm, markdorison, Alienpruts, lokapujya, Wim...

Status: Fixed » Closed (fixed)

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