You are here

class CurrentPathAlias in More Global Variables 8

Class CurrentPathAlias.

@package Drupal\mgv\Plugin\GlobalVariable

@Mgv( id = "current_path_alias", );

Hierarchy

Expanded class hierarchy of CurrentPathAlias

File

src/Plugin/GlobalVariable/CurrentPathAlias.php, line 16

Namespace

Drupal\mgv\Plugin\GlobalVariable
View source
class CurrentPathAlias extends GlobalVariable {

  /**
   * {@inheritdoc}
   */
  public function getValue() {

    // Print the current path alias. This could be useful if you want to ensure
    // the alias rather than the path is used.
    $current_path = \Drupal::service('path.current')
      ->getPath();
    return \Drupal::service('path_alias.manager')
      ->getAliasByPath($current_path);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrentPathAlias::getValue public function Method that implement generating value of global variable. Overrides GlobalVariableInterface::getValue
GlobalVariable::$configurations private property
GlobalVariable::$dependency private property
GlobalVariable::getDependency public function Dependency getter.
GlobalVariable::__construct public function GlobalVariable constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.