function _ccl_prepare_link in Custom Contextual Links 8
Same name and namespace in other branches
- 7 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 162 - Main CCL module file.
Code
function _ccl_prepare_link($link, $destination, $node = NULL) {
// Token replacement for the URL.
$link['href'] = $node ? \Drupal::token()
->replace($link['href'], array(
'node' => $node,
)) : \Drupal::token()
->replace($link['href']);
// Check the access permission.
if (\Drupal::service("path.validator")
->isValid($link['href'], TRUE)) {
// Token replacement for the title.
$link['title'] = $node ? \Drupal::token()
->replace($link['title'], array(
'node' => $node,
)) : \Drupal::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 (!\Drupal\Component\Utility\UrlHelper::isExternal($link['href']) && (!isset($link['advanced']['destination']) || $link['advanced']['destination'])) {
$link['query'] = $destination;
}
if (isset($link['advanced']['query']) && !empty($link['advanced']['query'])) {
$query = $node ? \Drupal::token()
->replace($link['advanced']['query'], array(
'node' => $node,
)) : \Drupal::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;
}
}