You are here

public function NodeTitleCoder::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/NodeTitleCoder.php, line 28

Class

NodeTitleCoder
Node title facets pretty paths coder.

Namespace

Drupal\facets_pretty_paths\Plugin\facets_pretty_paths\coder

Code

public function encode($nid) {
  if ($node = Node::load($nid)) {
    $label = $node
      ->label();
    $label = \Drupal::service('pathauto.alias_cleaner')
      ->cleanString($label);
    return $label . '-' . $nid;
  }
  return $nid;
}