You are here

public function TaxonomyTermCoder::encode in Facets Pretty Paths 8

Encode an id into an alias.

Parameters

string $id: An entity id.

Return value

string An alias.

Overrides CoderInterface::encode

File

src/Plugin/facets_pretty_paths/coder/TaxonomyTermCoder.php, line 28

Class

TaxonomyTermCoder
Banana facets pretty paths coder.

Namespace

Drupal\facets_pretty_paths\Plugin\facets_pretty_paths\coder

Code

public function encode($id) {
  if ($term = Term::load($id)) {
    $term_name = $term
      ->get('name')->value;
    $term_name = \Drupal::service('pathauto.alias_cleaner')
      ->cleanString($term_name);
    return $term_name . '-' . $id;
  }
  return $id;
}