ccl.module in Custom Contextual Links 8.2
Same filename and directory in other branches
Contains ccl.module.
File
ccl.moduleView source
<?php
/**
* @file
* Contains ccl.module.
*/
use Drupal\node\Entity\Node;
/**
* Implements hook_contextual_links_view_alter().
*/
function ccl_contextual_links_view_alter(&$element, $items) {
if (isset($element['#contextual_links']['node'])) {
$nid = $element['#contextual_links']['node']['route_parameters']['node'];
/** @var \Drupal\ccl\CclService $cclService */
$cclService = Drupal::service('ccl.service');
$node = Node::load($nid);
$cache = $cclService
->getCachedLinks('ccl:nodes');
// Global links.
foreach ($cache['globalLinks'] as $id => $link) {
if ($processedLink = $cclService
->prepareLink($link, $node)) {
$element['#links']['ccl-node-global-' . $id] = $processedLink;
}
}
// Content type specific links.
$contentType = $node
->bundle();
if ($contentType) {
foreach ($cache['contentTypeLinks'][$contentType] as $id => $ct_link) {
if ($processedLink = $cclService
->prepareLink($ct_link, $node)) {
$element['#links']['ccl-node-ct-' . $id] = $processedLink;
}
}
}
// Individual nodes.
if (isset($cache['nodeLinks'][$nid])) {
foreach ($cache['nodeLinks'][$nid] as $id => $link) {
if ($processedLink = $cclService
->prepareLink($link, $node)) {
$element['#links']['ccl-node-id-' . $id] = $processedLink;
}
}
}
}
// Invoke submodules.
foreach (Drupal::moduleHandler()
->getImplementations('ccl_add_link') as $module) {
$element = Drupal::moduleHandler()
->invoke($module, 'ccl_add_link', [
$element,
]);
}
}
Functions
Name | Description |
---|---|
ccl_contextual_links_view_alter | Implements hook_contextual_links_view_alter(). |