1

I'm trying to enhance the frontpage teaser's contextual links. On front page content we click on Configure link, and it shows Edit, Delete and Node Export by default.

I'd like to also add a Unpromote from/to frontpage link.

Is this possible? If so, how can it be achieved?

1

Contextual links can be added by adding a menu item (e.g. hook_menu() or hook_menu_alter()) and setting context to MENU_CONTEXT_INLINE & type to MENU_LOCAL_ACTION. For node actions, you can add a menu item to the node/% route. The nid argument can be passed through so you can execute your appropriate node frontpage toggle logic.

For example:

/**
 * implements hook_menu_alter().
 */
function MYMODULE_menu_alter(&$items) {
  $items['node/%/frontpage'] = array(
    'title' => 'Toggle Frontpage Status',
    'type' => MENU_LOCAL_ACTION,
    'context' => MENU_CONTEXT_INLINE,
    'page callback' => 'MYMODULE_toggle_frontpage',
    'page arguments' => array(1),
    'access arguments' => array('administer content'),
  );
}

function MYMODULE_toggle_frontpage($nid) {
  // @TODO: Add your $node->promote switching logic.

  // Jump back to the original page containing the context menu.
  drupal_goto(drupal_get_destination());
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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