function contextual_pre_render_links

Build a renderable array for contextual links.

Parameters

$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',
                'navigation',
            ),
        ),
        'menu' => array(
            'admin/structure/menu/manage',
            array(
                'navigation',
            ),
        ),
    ),
);

Return value

A renderable array representing contextual links.

See also

menu_contextual_links()

contextual_element_info()

1 string reference to 'contextual_pre_render_links'
contextual_element_info in modules/contextual/contextual.module
Implements hook_element_info().

File

modules/contextual/contextual.module, line 137

Code

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 = drupal_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'] += drupal_get_destination();
        $links[$class] += $item['localized_options'];
    }
    $element['#links'] = $links;
    // Allow modules to alter the renderable contextual links element.
    drupal_alter('contextual_links_view', $element, $items);
    // If there are no links, tell drupal_render() to abort rendering.
    if (empty($element['#links'])) {
        $element['#printed'] = TRUE;
    }
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.