You are here

class Token in Bamboo Twig 8.3

Same name and namespace in other branches
  1. 8.5 bamboo_twig_token/src/TwigExtension/Token.php \Drupal\bamboo_twig_token\TwigExtension\Token
  2. 8.2 bamboo_twig_token/src/TwigExtension/Token.php \Drupal\bamboo_twig_token\TwigExtension\Token
  3. 8.4 bamboo_twig_token/src/TwigExtension/Token.php \Drupal\bamboo_twig_token\TwigExtension\Token

Provides a token rempalcement as Twig Extensions.

Hierarchy

  • class \Drupal\bamboo_twig\TwigExtension\TwigExtensionBase extends \Drupal\bamboo_twig\TwigExtension\Twig_Extension uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
    • class \Drupal\bamboo_twig_token\TwigExtension\Token

Expanded class hierarchy of Token

1 string reference to 'Token'
bamboo_twig_token.services.yml in bamboo_twig_token/bamboo_twig_token.services.yml
bamboo_twig_token/bamboo_twig_token.services.yml
1 service uses Token
bamboo_twig_token.twig.token in bamboo_twig_token/bamboo_twig_token.services.yml
Drupal\bamboo_twig_token\TwigExtension\Token

File

bamboo_twig_token/src/TwigExtension/Token.php, line 10

Namespace

Drupal\bamboo_twig_token\TwigExtension
View source
class Token extends TwigExtensionBase {

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

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

  /**
   * Substitute a given tokens with appropriate value.
   *
   * @param string $token
   *   A replaceable token.
   * @param array $data
   *   (optional) An array of keyed objects. For simple replacement scenarios
   *   'node', 'user', and others are common keys, with an accompanying node or
   *   user object being the value. Some token types, like 'site', do not
   *   require any explicit information from $data and can be replaced even if
   *   it is empty.
   * @param array $options
   *   (optional) A keyed array of settings and flags to control the token
   *   replacement process.
   *
   * @return string
   *   The token value.
   *
   * @see \Drupal\Core\Utility\Token::replace()
   */
  public function substituteToken($token, array $data = [], array $options = []) {
    return $this
      ->getToken()
      ->replace("[{$token}]", $data, $options);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Token::getFunctions public function List of all Twig functions.
Token::getName public function Unique identifier for this Twig extension. Overrides TwigExtensionBase::getName
Token::substituteToken public function Substitute a given tokens with appropriate value.
TwigExtensionBase::getBlockStorage protected function Return the block storage.
TwigExtensionBase::getConfigFactory protected function Provides an interface for a configuration object factory.
TwigExtensionBase::getCurrentRouteMatch protected function Return the current route match.
TwigExtensionBase::getCurrentUser protected function Lazy loading for the Drupal current user account proxy.
TwigExtensionBase::getDateFormatter protected function Provides a service to handle various date related functionality.
TwigExtensionBase::getEntityTypeManager protected function Lazy loading for the Drupal entity type manager.
TwigExtensionBase::getExtensionGuesser protected function Return a singleton mime type to file extension guesser.
TwigExtensionBase::getFieldTypeManager protected function Return the factory for image objects.
TwigExtensionBase::getFileStorage protected function Return the file storage.
TwigExtensionBase::getFileSystemObject protected function Provides helpers to operate on files and stream wrappers.
TwigExtensionBase::getFormBuilder protected function Provides an interface for form building and processing.
TwigExtensionBase::getImageFactory protected function Return the factory for image objects.
TwigExtensionBase::getImageStyleStorage protected function Provides an interface defining an image style.
TwigExtensionBase::getLanguageManager protected function Returns the language manager service.
TwigExtensionBase::getMenuLinkTree protected function Interface for loading, transforming and rendering menu link trees.
TwigExtensionBase::getPluginManagerBlock protected function Manages discovery and instantiation of block plugins.
TwigExtensionBase::getSettingsSingleton protected function Read only settings singleton.
TwigExtensionBase::getStateFactory protected function The state storage service.
TwigExtensionBase::getToken protected function Return the token service.
TwigExtensionBase::getUserStorage protected function Return the user storage.