View source
<?php
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
function cctags_help($path) {
switch ($path) {
case 'admin/help#cctags':
return t('Provides a tag cloud interface and additional processing capabilities dictionaries.');
}
}
function cctags_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'cctags/cctags_css';
}
function taxonomy_breadcrumb_block_delete(EntityInterface $entity) {
$conn = Database::getConnection();
$conn
->delete('cctags')
->condition('block_id', $entity
->id())
->execute();
}
function cctags_theme() {
return array(
'cctags_block' => array(
'variables' => array(
'cctid' => NULL,
'amount' => 0,
'extra_class' => '',
'more_link' => TRUE,
'content' => NULL,
),
),
'cctags_level' => array(
'variables' => array(
'terms' => NULL,
'amount' => 0,
'page' => 0,
'mode' => 'mixed',
'vocname' => 0,
'out' => 'block',
),
'function' => 'theme_cctags_level',
),
'cctags_term' => array(
'variables' => array(
'term' => NULL,
'mode' => NULL,
),
),
'cctags_vocname' => array(
'variables' => array(
'vocname' => NULL,
'vid' => NULL,
'terms' => 0,
'mode' => '',
'is_out' => array(),
),
),
'cctags_page' => array(
'variables' => array(
'cctid' => NULL,
'extra_class' => NULL,
'content' => NULL,
'pager' => NULL,
'taxonomy_terms' => NULL,
),
),
);
}
function cctags_get_level_tags($cctid, $mode = 'page') {
$language = \Drupal::languageManager()
->getCurrentLanguage();
$is_cache = \Drupal::config('cctags.settings')
->get('cctags_is_cache');
$terms = array();
$cache_name = NULL;
if ($mode == 'page') {
$cache_name = 'cctags_cache_page_' . $cctid . ':' . $language
->getId();
}
if ($mode == 'block') {
$cache_name = 'cctags_cache_block_' . $cctid . ':' . $language
->getId();
}
$items = _cctags_get_settings($cctid);
$item = $items[$cctid];
$terms = [];
foreach ($item['item_data'] as $key => $value) {
if ($value['cctags_select_' . $key]) {
$vocabulary = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadTree($key);
unset($value['cctags_select_' . $key]);
$levels_checked = [];
for ($i = 0; $i < count($value); $i++) {
if ($value['level_' . $i]) {
$levels_checked[] = $i;
}
}
foreach ($vocabulary as $term) {
if (in_array($term->depth, $levels_checked)) {
$terms[$key][$term->depth]['link'] = Link::fromTextAndUrl($term->name, Url::fromUri('base:/taxonomy/term/' . $term->tid));
$terms[$key][$term->depth]['url'] = '/taxonomy/term/' . $term->tid;
$terms[$key][$term->depth]['name'] = $term->name;
}
}
}
}
return $terms;
}
function _cctags_get_settings($cctid = NULL) {
$items = array();
$select = db_select('cctags', 'ct');
$select
->addField('ct', 'cctid');
$select
->addField('ct', 'name');
$select
->addField('ct', 'block');
$select
->addField('ct', 'block_id');
$select
->addField('ct', 'page');
$select
->addField('ct', 'page_title');
$select
->addField('ct', 'page_path');
$select
->addField('ct', 'page_level');
$select
->addField('ct', 'page_amount');
$select
->addField('ct', 'page_sort');
$select
->addField('ct', 'page_mode');
$select
->addField('ct', 'page_vocname');
$select
->addField('ct', 'page_extra_class');
$select
->addField('ct', 'item_data');
if ($cctid) {
$select
->condition('ct.cctid', $cctid);
}
$entries = $select
->execute()
->fetchAll();
foreach ($entries as $cctags) {
$items[$cctags->cctid] = array(
'cctid' => $cctags->cctid,
'name' => \Drupal\Component\Utility\SafeMarkup::checkPlain($cctags->name),
'block' => $cctags->block,
'block_id' => $cctags->block_id,
'page' => $cctags->page,
'page_title' => $cctags->page_title,
'page_path' => $cctags->page_path,
'page_level' => $cctags->page_level,
'page_amount' => $cctags->page_amount,
'page_sort' => $cctags->page_sort,
'page_mode' => $cctags->page_mode,
'page_vocname' => $cctags->page_vocname,
'page_extra_class' => $cctags->page_extra_class,
'item_data' => unserialize($cctags->item_data),
);
}
return $items;
}
function _cctags_get_select_list($type) {
$list = array();
switch ($type) {
case 'numtags':
$list = array_combine(array(
0,
4,
6,
8,
10,
12,
14,
16,
18,
20,
24,
28,
32,
40,
50,
60,
100,
120,
150,
200,
), array(
0,
4,
6,
8,
10,
12,
14,
16,
18,
20,
24,
28,
32,
40,
50,
60,
100,
120,
150,
200,
));
break;
case 'level':
$list = array_combine(array(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
), array(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
));
break;
case 'amount_tags':
$list = array_combine(array(
0,
6,
12,
14,
16,
18,
20,
24,
28,
32,
40,
50,
60,
100,
120,
150,
200,
300,
400,
500,
600,
900,
1400,
), array(
0,
6,
12,
14,
16,
18,
20,
24,
28,
32,
40,
50,
60,
100,
120,
150,
200,
300,
400,
500,
600,
900,
1400,
));
break;
}
return $list;
}
function theme_cctags_level($variables) {
$terms = $variables['terms'];
$amount = $variables['amount'];
$page = $variables['page'];
$out = $variables['out'];
$start_term = $amount * $page;
$term_out = [];
foreach ($terms as $vocbulary_name => $term_list) {
foreach ($term_list as $term) {
$term_out[] = [
'#theme' => 'cctags_term',
'#term' => $term['link']
->toString(),
'#mode' => $out,
];
}
}
return $term_out;
}