You are here

class Langs in Bamboo Twig 8

Provides a 'Langs' Twig Extensions.

Hierarchy

  • class \Drupal\bamboo_twig\TwigExtension\Langs extends \Drupal\bamboo_twig\TwigExtension\Twig_Extension

Expanded class hierarchy of Langs

1 string reference to 'Langs'
bamboo_twig.services.yml in ./bamboo_twig.services.yml
bamboo_twig.services.yml
1 service uses Langs
bamboo_twig.twig.langs in ./bamboo_twig.services.yml
Drupal\bamboo_twig\TwigExtension\Langs

File

src/TwigExtension/Langs.php, line 11

Namespace

Drupal\bamboo_twig\TwigExtension
View source
class Langs extends \Twig_Extension {

  /**
   * Language manager service.
   *
   * @var Drupal\Core\Language\LanguageManagerInterface
   */
  private $language;

  /**
   * TwigExtension constructor.
   */
  public function __construct(LanguageManagerInterface $language) {
    $this->language = $language;
  }

  /**
   * List of all Twig functions.
   */
  public function getFunctions() {
    return [
      new \Twig_SimpleFunction('get_lang', [
        $this,
        'getLang',
      ]),
    ];
  }

  /**
   * Unique identifier for this Twig extension.
   */
  public function getName() {
    return 'bamboo_twig.twig.langs';
  }

  /**
   * Retrieve the current language.
   */
  public function getLang() {
    return $this->language
      ->getCurrentLanguage()
      ->getId();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Langs::$language private property Language manager service.
Langs::getFunctions public function List of all Twig functions.
Langs::getLang public function Retrieve the current language.
Langs::getName public function Unique identifier for this Twig extension.
Langs::__construct public function TwigExtension constructor.