You are here

function cctags_get_level_tags in cctags 8

Same name and namespace in other branches
  1. 6 cctags.module \cctags_get_level_tags()
  2. 7 cctags.module \cctags_get_level_tags()

Function that gets the information from the database, passes it along to the weight builder and returns these weighted tags. Note that the tags are unordered at this stage, hence they need orndering either by calling our api or by your own ordering data.

Parameters

$cctid. Cctags IDs items.:

$mode. block or page parameters settings.:

Return value

An <em>unordered</em> array with tags-objects, containing the attribute $tag->weight,$tags->level ...;

2 calls to cctags_get_level_tags()
CctagsBlock::build in src/Plugin/Block/CctagsBlock.php
Builds and returns the renderable array for this block plugin.
CctagsController::content in src/Controller/CctagsController.php
Call back for route static_content.

File

./cctags.module, line 91

Code

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;
}