I've been making heavy use of Contextual Links in Drupal 7 projects, as they allow users to edit content on a site without having to navigate the admin interface.

It looks like Webform has contextual links for nodes, but they don't appear when a web form is a block – you get only the "Configure Block" link. Can we get this added?

#2 webform_contextual_links.patch1.12 KBquicksketch
Members fund testing for the Drupal project. Drupal Association Learn more


isaacfreeman’s picture

Here's a naive solution I've hacked together, based on notes at http://bleen.net/comment/3264

It directly adds a couple of links to the web form block. I'm sure it could be done better, and obviously it would be nicer to have the contextual links as standard in Webform.

function MODULENAME_contextual_links_view_alter(&$element, &$items) {
   if (isset($element['#element']['#block']) && $element['#element']['#block']->module == "webform"){
    $element['#links']['page-webform'] = array(
      'title' => 'Webform',
      'href' => 'node/' . $element['#element']['#node']->nid . '/webform',
   $element['#links']['page-results'] = array(
      'title' => 'Results',
      'href' => 'node/' . $element['#element']['#node']->nid . '/webform-results',
quicksketch’s picture

Status: Active » Fixed
1.12 KB

Sweet thanks! I've modified your code into this patch and included it in the project (7.x-3.x branch only of course).

quicksketch’s picture

Title: Contextual links for Webform Blocks » Contextual links for Webform Blocks and Nodes

Updating title. I modified your code so that the "Webform" and "Results" links show up on all webform-enabled nodes as well as in Webform blocks.

Status: Fixed » Closed (fixed)

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

David_Rothstein’s picture

This looks like a great start, but I'm running into a bug with it, and it also seems like the code can be simplified. I posted a patch at #1414666: Webform contextual links are shown to users who don't have access to them, and code can be simplified; reviews welcome if anyone has a chance.