You are here

function ccl_views_ccl_add_link in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl_views/ccl_views.module \ccl_views_ccl_add_link()

Hook function to process the contextual links element.

File

ccl_views/ccl_views.module, line 91
Implements support of views in CCL.

Code

function ccl_views_ccl_add_link($element, $dest) {

  // View processing.
  if (isset($element['#element']['#views_contextual_links_info'])) {
    $vid = $element['#element']['#views_contextual_links_info']['views_ui']['view_name'];
    $vdid = $element['#element']['#views_contextual_links_info']['views_ui']['view_name'] . '|' . $element['#element']['#views_contextual_links_info']['views_ui']['view_display_id'];
    $views_cache = ccl_cache_get('ccl_view');

    // Global Views.
    foreach ($views_cache['global'] as $id => $link) {
      if ($processed_link = _ccl_prepare_link($link, $dest)) {
        $element['#links']['ccl-global-view-' . $id] = $processed_link;
      }
    }

    // Individual view.
    if (in_array($vid, array_keys($views_cache['views']))) {
      foreach ($views_cache['views'][$vid] as $id => $link) {
        if ($processed_link = _ccl_prepare_link($link, $dest)) {
          $element['#links']['ccl-view-' . $id] = $processed_link;
        }
      }
    }

    // Individual display.
    if (in_array($vdid, array_keys($views_cache['displays']))) {
      foreach ($views_cache['displays'][$vdid] as $id => $link) {
        if ($processed_link = _ccl_prepare_link($link, $dest)) {
          $element['#links']['ccl-display-' . $id] = $processed_link;
        }
      }
    }
  }
  return $element;
}