function ccl_contextual_links_view_alter in Custom Contextual Links 7
Same name and namespace in other branches
- 8.2 ccl.module \ccl_contextual_links_view_alter()
- 8 ccl.module \ccl_contextual_links_view_alter()
Implements hook_contextual_links_view_alter().
TODO:
- Make sure all links are work in a multilanguage setup.
File
- ./
ccl.module, line 106 - Main CCL module file.
Code
function ccl_contextual_links_view_alter(&$element, $items) {
// Get the destination parameter.
$dest = drupal_get_destination();
// Check if we have a node link to process.
if (isset($element['#element']['#node']->nid)) {
$node = $element['#element']['#node'];
$node_cache = ccl_cache_get('ccl_nodes');
// Global elements.
if (is_array($node_cache)) {
foreach ($node_cache['global'] as $id => $link) {
if ($processed_link = _ccl_prepare_link($link, $dest, $node)) {
$element['#links']['ccl-global-node-' . $id] = $processed_link;
}
}
}
// Content Type.
if (is_array($node_cache['ct']) && in_array($node->type, array_keys($node_cache['ct']))) {
foreach ($node_cache['ct'][$node->type] as $id => $link) {
if ($processed_link = _ccl_prepare_link($link, $dest, $node)) {
$element['#links']['ccl-ct-' . $id] = $processed_link;
}
}
}
// Individual nodes.
if (is_array($node_cache['ids']) && in_array($node->nid, array_keys($node_cache['ids']))) {
foreach ($node_cache['ids'][$node->nid] as $id => $link) {
if ($processed_link = _ccl_prepare_link($link, $dest, $node)) {
$element['#links']['ccl-node-' . $id] = $processed_link;
}
}
}
}
// Invoke submodules.
foreach (module_implements('ccl_add_link') as $module) {
$element = module_invoke($module, 'ccl_add_link', $element, $dest);
}
}