I have a contextual link on a block that will take the user to an admin screen with a delete button on the admin screen. The delete button works fine when not coming from the contextual link. I noticed the contextual link adds "destination=node" to the end of the URL. The fact that the contextual link adds that to the URL does not allow for my admin screen to redirect to the delete confirm admin screen. If i remove the "destination=node" from the admin screen URL, it goes to the delete confirm admin screen with no issues. Has anyone else had this issue? I noticed this is for absolutely any module or block in drupal. If going to the admin screen from a contextual link and it has a delete button on the admin screen, the delete functionality will not work! Any suggestions?

2 Answers 2


hook_menu_contextual_links_alter() allows you to go in and change anything your heart desires. :)

  • But not destination=path/to/where/was In $links['node-edit'] for example, the options and localized_options are empty arrays.
    – mlncn
    Commented Sep 18, 2014 at 20:00

The accepted answer is not entirely correct. When hook_menu_contextual_links_alter() gets to act on the array of contextual links, no destinations have been set yet.

Instead, just a few lines after menu_contextual_links() (and so its alter hook) is called in contextual_pre_render_links(), there is this line adding the destination to the contextual link:

$item['localized_options']['query'] += drupal_get_destination();

If you set a query destination in hook_menu_contextual_links_alter(), the one you set will win. But if you just want to get rid of the destination so for instance a redirect set in the form can do its thing (including, say, adding a fragment)... removing the destination before it is added here doesn't work.

This being Drupal, however, two lines later another alter hook is called:

drupal_alter('contextual_links_view', $element, $items);

(This is all in contextual module.)

So implement that hook instead. For a module named example removing the destination from all node edit alter hooks on a given array of content type machine names available with the function example_selected_node_types(), the implementation would look like this:

 * Implements hook_contextual_links_view_alter().
function example_contextual_links_view_alter(&$element, $items) {
  if (isset($element['#element']['#entity_type']) &&
      $element['#element']['#entity_type'] == 'node' &&
    $element['#links']['node-edit']['query'] = array();

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.