You are here

public function IndexNameDepth::title in Views Taxonomy Term Name Depth 7.x

Same name and namespace in other branches
  1. 8.6 src/Plugin/views/argument/IndexNameDepth.php \Drupal\views_taxonomy_term_name_depth\Plugin\views\argument\IndexNameDepth::title()
  2. 8 src/Plugin/views/argument/IndexNameDepth.php \Drupal\views_taxonomy_term_name_depth\Plugin\views\argument\IndexNameDepth::title()
  3. 8.3 src/Plugin/views/argument/IndexNameDepth.php \Drupal\views_taxonomy_term_name_depth\Plugin\views\argument\IndexNameDepth::title()

Get the title this argument will assign the view, given the argument.

This usually needs to be overridden to provide a proper title.

Overrides ArgumentPluginBase::title

File

src/Plugin/views/argument/IndexNameDepth.php, line 249

Class

IndexNameDepth
Argument handler for taxonomy terms with depth.

Namespace

Drupal\views_taxonomy_term_name_depth\Plugin\views\argument

Code

public function title() {
  $term = $this->termStorage
    ->load($this->argument);

  // Check the use of pathauto module.
  if ($this->moduleHandler
    ->moduleExists('pathauto')) {
    $query = $this->database
      ->select('taxonomy_term_field_data', 't')
      ->fields('t', [
      'tid',
      'name',
    ]);

    // Filter by vocabulary ID if one or more are provided.
    if (!empty($this->options['vocabularies'])) {
      $query
        ->condition('t.vid', $this->options['vocabularies'], 'IN');
    }
    $results = $query
      ->execute()
      ->fetchAll(\PDO::FETCH_OBJ);

    // Iterate results.
    foreach ($results as $row) {

      // Service container for alias cleaner.
      if ($this->pathautoAliasCleaner
        ->cleanString($row->name) == $this->pathautoAliasCleaner
        ->cleanString($this->argument)) {
        $tid = $row->tid;
        $term = current($this->termStorage
          ->loadByProperties([
          'tid' => $tid,
        ]));
        break;
      }
    }
  }

  // If no term was loaded in the pathauto verification, try one more time
  // before 'no name'.
  if (empty($term)) {
    $term = current($this->termStorage
      ->loadByProperties([
      'name' => str_replace('-', ' ', $this->argument),
    ]));
  }
  if (!empty($term)) {
    return $term
      ->getName();
  }
}