You are here

function _ccl_prepare_link in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl.module \_ccl_prepare_link()

Helper function for token replacement, destination and access control.

4 calls to _ccl_prepare_link()
ccl_blocks_ccl_add_link in ccl_blocks/ccl_blocks.module
Hook function to process the contextual links element.
ccl_contextual_links_view_alter in ./ccl.module
Implements hook_contextual_links_view_alter().
ccl_local_actions_menu_local_tasks_alter in ccl_local_actions/ccl_local_actions.module
Implements hook_menu_local_tasks_alter().
ccl_views_ccl_add_link in ccl_views/ccl_views.module
Hook function to process the contextual links element.

File

./ccl.module, line 164
Main CCL module file.

Code

function _ccl_prepare_link($link, $destination, $node = NULL) {

  // Token replacement for the URL.
  $link['href'] = $node ? token_replace($link['href'], array(
    'node' => $node,
  )) : token_replace($link['href']);

  // Check the access permission.
  if (drupal_valid_path($link['href'], TRUE)) {

    // Token replacement for the title.
    $link['title'] = $node ? token_replace($link['title'], array(
      'node' => $node,
    )) : token_replace($link['title']);

    // Add classes if available.
    if (isset($link['advanced']['class'])) {
      $link['attributes']['class'] = explode(" ", $link['advanced']['class']);
    }

    // Add link target if set.
    if (isset($link['advanced']['target'])) {
      $link['attributes']['target'] = explode(" ", $link['advanced']['target']);
    }

    // Add anchor if available
    if (isset($link['advanced']['anchor'])) {
      $link['fragment'] = $link['advanced']['anchor'];
    }

    // Add query if available and destination.
    if (!url_is_external($link['href']) && (!isset($link['advanced']['destination']) || $link['advanced']['destination'])) {
      $link['query'] = $destination;
    }
    if (isset($link['advanced']['query']) && !empty($link['advanced']['query'])) {
      $query = $node ? token_replace($link['advanced']['query'], array(
        'node' => $node,
      )) : token_replace($link['advanced']['query']);
      $qparts = explode('&', $query);
      foreach ($qparts as $value) {
        $kv = explode('=', $value);
        $link['query'][$kv[0]] = $kv[1];
      }
    }
    return $link;
  }
  else {
    return FALSE;
  }
}