You can put tokens in your module at using hook_token_info() to register them and hook_tokens() for the the replacement data. ![]() If a module needs to show the list of available tokens, it must build the list of the tokens itself and show it in the description of a form field alternatively, it can use the theme function still available in the Token module.įor Drupal 8, example using the node object: In Drupal 7, there isn't any function that show the list of the available tokens.In Drupal 7, there are not raw tokens the implementation of hook_tokens() get a parameter that tells to the hook when the content of the token needs to be sanitized when the token value doesn't need to be sanitized, the content is not passed to the functions check_plain() or filter_xss().In other words, it is possible to use, where "xyz" is one of the tokens returned for a user object. In Drupal 7, returns the name of the author returns the email address associated with the author of a node, and returns the URL of the user profile for the node author. ![]() Other difference between the Token module for Drupal 6 and the code in Drupal 7 are: The function that in Drupal 7 is used to replace the tokens with their value is token_replace(), which is the only function used to replace the tokens with their values. In Drupal 7, the implementation of hook_tokens() receives $tokens, an array of tokens to be replaced, as argument the module is then able to compute the value of a token, knowing it will be used. In Drupal 6, the Token module would ask to the modules implementing tokens all the values for their token using hook_token_values() this means that a module can compute the value for a token which is then not required for the tokens being replaced. Other modules can alter the token implementation provided from a module using hook_token_info_alter() and hook_tokens_alter().ĭifferently from the Token module, the code in Drupal core allows to create the content of a token only when strictly necessary. hook_tokens() is the hook that needs to be implemented to provide the actual values that replace the tokens.hook_token_info() is the hook that provides information about the tokens implemented by a module.The hooks the token modules need to implement are: ![]() In Drupal 7 the code for handling tokens is part of the Drupal core module.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |