Skip to content

Instantly share code, notes, and snippets.

@bangpound
Created February 9, 2011 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bangpound/817801 to your computer and use it in GitHub Desktop.
Save bangpound/817801 to your computer and use it in GitHub Desktop.
add manage field and display contextual links to nodes.
<?php
/**
* Implement hook_menu_alter().
*/
function bangpound_menu_alter(&$items) {
if (module_exists('field_ui')) {
$items['admin/structure/types/manage/%node_type/fields']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
$items['admin/structure/types/manage/%node_type/display']['context'] = MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE;
}
}
/**
* Implement hook_node_view_alter().
*
* Contextual links are added after hook_node_view() in node_view(), so
* use hook_node_view_alter() to add the node's links.
*/
function bangpound_node_view_alter(&$build) {
$node = $build['#node'];
$view_mode = $build['#view_mode'];
if (!empty($node->nid)) {
// Field UI doesn't provide its own contextual links, so we pretend to be
// Field UI. This could backfire.
$build['#contextual_links']['field_ui'] = array('admin/structure/types/manage', array($node->type));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment