In this article, I'll show you how to create Token Drupal to return absolute url without language prefix.
Follow the instructions below:
Create absolute_url.info.yml file:
Create absolute_url.module file:
The first thing we’ll need in this file is, hook_tokens_info()
This is where we’ll define our tokens for Drupal. Which will make your new token available in UI.
In the second half of the code, the hook_tokens()
function is used to actually make the token perform its desired function.
Clear your Drupal 8 caches, and then your new token will be available in UI.
Next steps
- Clear your Drupal caches. To do this I use this Drush command:
drush cr
if you don’t currently use Drush, I highly recommend using it, or the Drupal Console. - Now, go back to your site, and you should be able to see the new custom token.
- I hope you found this article useful. let me know if you have any questions and I’ll be happy to answer them.