1 contextual.module contextual_pre_render_links($element)

Pre-render callback: Builds a renderable array for contextual links.


$element: A renderable array containing a #contextual_links property, which is a keyed array. Each key is the name of the implementing module, and each value is an array that forms the function arguments for menu_contextual_links(). For example:

    array('#contextual_links' => array(
      'block' => array('admin/structure/block/manage', array('system', 'management')),
      'menu' => array('admin/structure/menu/manage', array('management')),

Return value

A renderable array representing contextual links.:

See also




core/modules/contextual/contextual.module, line 119
Adds contextual links to perform actions related to elements on a page.


function contextual_pre_render_links($element) {
  // Retrieve contextual menu links.
  $items = array();
  foreach ($element['#contextual_links'] as $module => $args) {
    $items += menu_contextual_links($module, $args[0], $args[1]);

  // Transform contextual links into parameters suitable for theme_link().
  $links = array();
  foreach ($items as $class => $item) {
    $class = backdrop_html_class($class);
    $links[$class] = array(
      'title' => $item['title'],
      'href' => $item['href'],
    // @todo theme_links() should *really* use the same parameters as l().
    $item['localized_options'] += array('query' => array());
    $item['localized_options']['query'] += backdrop_get_destination();
    $links[$class] += $item['localized_options'];
  $element['#links'] = $links;

  // Allow modules to alter the renderable contextual links element.
  backdrop_alter('contextual_links_view', $element, $items);

  // If there are no links, tell backdrop_render() to abort rendering.
  if (empty($element['#links'])) {
    $element['#printed'] = TRUE;

  return $element;