You are here

public function CloudBuilder::build in TagCloud 1.0.x

Same name and namespace in other branches
  1. 8 src/CloudBuilder.php \Drupal\tagclouds\CloudBuilder::build()
  2. 2.0.x src/CloudBuilder.php \Drupal\tagclouds\CloudBuilder::build()

Returns a render array for the tags.

Parameters

array $terms: A list of tags to render.

Overrides CloudBuilderInterface::build

File

src/CloudBuilder.php, line 36

Class

CloudBuilder
Class CloudBuilder.

Namespace

Drupal\tagclouds

Code

public function build(array $terms) {
  $output = [];
  $config = $this->configFactory
    ->getEditable('tagclouds.settings');
  $display = $config
    ->get('display_type');
  if (empty($display)) {
    $display = 'style';
  }
  if ($display == 'style') {
    foreach ($terms as $term) {
      $term_name = $term->name;
      $term_desc = $term->description__value;
      if ($term->count == 1 && $config
        ->get("display_node_link")) {
        $output[$term->tid] = $this
          ->displayNodeLinkWeight($term_name, $term->tid, $term->nid, $term->weight, $term_desc);
      }
      else {
        $output[$term->tid] = $this
          ->displayTermLinkWeight($term_name, $term->tid, $term->weight, $term_desc);
      }
    }
  }
  else {
    foreach ($terms as $term) {
      $term_name = $term->name;
      $term_desc = $term->description__value;
      if ($term->count == 1 && $config
        ->get("display_node_link")) {
        $output[$term->tid] = $this
          ->displayNodeLinkCount($term_name, $term->tid, $term->nid, $term->count, $term_desc);
      }
      else {
        $output[$term->tid] = $this
          ->displayTermLinkCount($term_name, $term->tid, $term->count, $term_desc);
      }
    }
  }
  return $output;
}