- <?php
-
- * @file
- * Adds contextual links to perform actions related to elements on a page.
- */
-
- * Implements hook_permission().
- */
- function contextual_permission() {
- return array(
- 'access contextual links' => array(
- 'title' => t('Use contextual links'),
- 'description' => t('Use contextual links to perform actions related to elements on a page.'),
- ),
- );
- }
-
- * Implements hook_library_info().
- */
- function contextual_library_info() {
- $path = backdrop_get_path('module', 'contextual');
- $libraries['contextual-links'] = array(
- 'title' => 'Contextual Links',
- 'website' => 'http://drupal.org/node/473268',
- 'version' => BACKDROP_VERSION,
- 'js' => array(
- $path . '/js/contextual.js' => array(),
- ),
- 'css' => array(
- $path . '/css/contextual.css' => array(),
- ),
- );
- return $libraries;
- }
-
- * Implements hook_element_info().
- */
- function contextual_element_info() {
- $types['contextual_links'] = array(
- '#pre_render' => array('contextual_pre_render_links'),
- '#theme' => 'links__contextual',
- '#links' => array(),
- '#prefix' => '<div class="contextual-links-wrapper">',
- '#suffix' => '</div>',
- '#attributes' => array(
- 'class' => array('contextual-links'),
- ),
- '#attached' => array(
- 'library' => array(
- array('contextual', 'contextual-links'),
- ),
- ),
- );
- return $types;
- }
-
- * Implements hook_preprocess().
- *
- * @see contextual_pre_render_links()
- */
- function contextual_preprocess(&$variables, $hook) {
-
- if (!user_access('access contextual links')) {
- return;
- }
-
- $hooks = theme_get_registry(FALSE);
-
-
- if (!empty($hooks[$hook]['variables'])) {
- $keys = array_keys($hooks[$hook]['variables']);
- $key = $keys[0];
- }
- elseif (!empty($hooks[$hook]['render element'])) {
- $key = $hooks[$hook]['render element'];
- }
- if (!empty($key) && isset($variables[$key])) {
- $element = $variables[$key];
- }
-
- if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
-
- $variables['title_suffix']['contextual_links'] = array(
- '#type' => 'contextual_links',
- '#contextual_links' => $element['#contextual_links'],
- '#element' => $element,
- );
-
- $variables['classes'][] = 'contextual-links-region';
- unset($element['#contextual_links']);
- }
- }
-
- * Pre-render callback: Builds a renderable array for contextual links.
- *
- * @param $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:
- * @code
- * array('#contextual_links' => array(
- * 'block' => array('admin/structure/block/manage', array('system', 'management')),
- * 'menu' => array('admin/structure/menu/manage', array('management')),
- * ))
- * @endcode
- *
- * @return
- * A renderable array representing contextual links.
- *
- * @see menu_contextual_links()
- * @see contextual_element_info()
- */
- function contextual_pre_render_links($element) {
-
- $items = array();
- foreach ($element['#contextual_links'] as $module => $args) {
- $items += menu_contextual_links($module, $args[0], $args[1]);
- }
-
-
- $links = array();
- foreach ($items as $class => $item) {
- $class = backdrop_html_class($class);
- $links[$class] = array(
- 'title' => $item['title'],
- 'href' => $item['href'],
- );
-
- $item['localized_options'] += array('query' => array());
- $item['localized_options']['query'] += backdrop_get_destination();
- $links[$class] += $item['localized_options'];
- }
- $element['#links'] = $links;
-
-
- backdrop_alter('contextual_links_view', $element, $items);
-
-
- if (empty($element['#links'])) {
- $element['#printed'] = TRUE;
- }
-
- return $element;
- }
-