0

I want to show contextual links having Edit and delete links for each node on hover on main listing page of my application. I have searched and found the following code

function MyModule_node_view_alter(&$build) {
  if(isset($build['#node'])) {
        $node = $build['#node'];
        if(!empty($node->nid)) {
            $build['#contextual_links']['node'] = array('node', array($node->nid));
        }
    }
}

But this code displays contextual link on node detail page. For example when individual node is visited like http://www.example.com/node/21. But I want to show these contextual link on listing page where all nodes are displayed. When I hover the node, this should be shown.

This is how my view settings looks like

enter image description here

Any help?

0

1 Answer 1

2

If you are building the node listing page using views, you can

  1. Enable contextual links module.
  2. In the fields for the listing, add a field 'Content : Edit Link'. Then select Exclude from display.
  3. Add a Global : Contextual Links field. In the field settings, check the edit link field.
  4. You should be good to go.
  5. You can also add additional field in the context menu if you want.

enter image description here

5
  • I followed your instructions. But it override my already display contextual link for the whole view. And it is only displaying against one node. I don't want to override or remove my global contextual link for all view. I want contextual link against each node along with that global contextual link. Jun 23, 2014 at 8:02
  • As you can see in the image I have uploaded now, the contextual links is being shown for each of the nodes listed in the views.
    – Gokul N K
    Jun 23, 2014 at 8:07
  • I again tried and followed all the steps as you mentioned. But it is only showing one contextual link for all view. I want to show it for all nodes in a view. It also replaces my global contextual link Jun 24, 2014 at 4:54
  • Can you share a screenshot of your view settings.
    – Gokul N K
    Jun 24, 2014 at 6:29
  • updated my question Jun 24, 2014 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.