Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Token module in drupal 8

2,902 views

Published on

In this presentation, Mashirul Haque, Drupal Consultant, has explained Token Module, its uses and how to create custom Tokens in Drupal 8. Basically, Token Module provides an API that is used to provide tokens for all other core or contributed module in a bunch.

The presentation also contains working example showing how to create custom tokens and use it.
----------------------------------------------------------
Get Socialistic

Our website: http://valuebound.com/
LinkedIn: http://bit.ly/2eKgdux
Facebook: https://www.facebook.com/valuebound/
Twitter: http://bit.ly/2gFPTi8

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Token module in drupal 8

  1. 1. Token module in Drupal 8 Mashirul Haque https://www.drupal.org/u/mashir
  2. 2. Agenda ● What is Token? ● What Token module does? ● How to create a custom token Programatically?
  3. 3. What is Token? Token is a small bits of text, which can be placed into a large documents as a simple placeholders.
  4. 4. What Token module does? The Token module provides an API to provide tokens for other modules. It also provide some additional tokens and provide a browsing facility for all available tokens in UI.
  5. 5. How to create a custom token Programatically? Two hooks are required to create a custom token. ● hook_token_info() ● hook_tokens()
  6. 6. hook_token_info() It provides information of available placeholders and Token types. Return Value: It returns an array of all available tokens and token type.
  7. 7. It provides the replacement value of placeholder tokens. Parameters: ● $type: Machine name of type of token ● $tokens: Array of tokens ● $data: Array of data objects ● $options: Array of options for token replacement hook_tokens()
  8. 8. hook_tokens() Parameters: ● DrupalCoreRenderBubbleableMetadata $bubbleable_metadata: Bubbleable metadata. Return value: It return an associative array of replacement values.
  9. 9. Other Token hooks: 1. hook_token_info_alter() Parameter: $data - Array of tokens. 2. hook_tokens_alter() Parameter: $replacements - Array of replacements return by hook_tokens(). $context - Array of all keys of hook_tokens().
  10. 10. DEMO
  11. 11. THANKS

×