- π©πͺGermany captain hindsight
Thought about the same but in a different way.
For the example above
[node:field_hero_image:entity:field_media_image:og_image|"/themes/custom/my_theme/image.png"]
why not extend it like that:
[node:field_hero_image:entity:field_media_image:og_image|site:base-url"/themes/custom/my_theme/image.png"]
I think this could be achieved by adding another condition in TokenOrTokensPreAlter::tokensPreAlter:
diff --git a/src/TokenOrTokensPreAlter.php b/src/TokenOrTokensPreAlter.php index f57cace..0d34def 100644 --- a/src/TokenOrTokensPreAlter.php +++ b/src/TokenOrTokensPreAlter.php @@ -44,10 +44,16 @@ class TokenOrTokensPreAlter { $sub_tokens = explode('|', $match_clean); foreach ($sub_tokens as $sub_token) { + $sub_token_matches = []; if (substr($sub_token, 0, 1) === '"' && substr($sub_token, -1, 1) === '"') { // This is a string replacement. $result = substr(substr($sub_token, 1), 0, -1); } + elseif (preg_match('/([^"]*)"(.*?)"/', $sub_token, $sub_token_matches)) { + // This is a token replacement with an appended string. + $result = $this->token->replace('[' . $sub_token_matches[1] . ']', $data, $options); + $result .= $result ? $sub_token_matches[2] : ''; + } else { // This is a token replacement. $result = $this->token->replace('[' . $sub_token . ']', $data, $options);
- πΊπΈUnited States pianomansam
@captain hindsight I think your solution could work. Feel free to create an issue fork to test that out.
- π»π³Vietnam zipme_hkt
@captain hindsight, with your case you can look this module https://www.drupal.org/project/token_eca_alter β
You can easy alter, extend exist token data.
- π©πͺGermany captain hindsight
Thanks, I discovered there is a hook `hook_tokens_pre_alter` which fullfills all my needs to do that.
I didn't notice that at the beginning because there is no api.php and I discovered it only by inspecting the code of token_or.
@pianomansam Maybe you could create a `token_or.api.php` ?
- πΊπΈUnited States pianomansam
@captain hindsight Always open to pull requests!