You are here

function ccl_blocks_ccl_add_link in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl_blocks/ccl_blocks.module \ccl_blocks_ccl_add_link()

Hook function to process the contextual links element.

File

ccl_blocks/ccl_blocks.module, line 75
Implments support for CCL on blocks.

Code

function ccl_blocks_ccl_add_link($element, $dest) {

  // Check if it is a block.
  if (isset($element['#element']['#block']->delta)) {
    $bid = $element['#element']['#block']->module . '|' . $element['#element']['#block']->delta;
    $block_cache = ccl_cache_get('ccl_blocks');

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

    // Individual blocks.
    if (in_array($bid, array_keys($block_cache['ids']))) {
      foreach ($block_cache['ids'][$bid] as $id => $link) {
        if ($processed_link = _ccl_prepare_link($link, $dest)) {
          $element['#links']['ccl-block-' . $id] = $processed_link;
        }
      }
    }
  }
  return $element;
}