Show contextual link for each node on node listing page 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(&amp;$build) {
  if(isset($build['#node'])) {
        $node = $build['#node'];
        if(!empty($node-&gt;nid)) {
            $build['#contextual_links']['node'] = array('node', array($node-&gt;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



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


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