Active
Project:
Token OR
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
4 Aug 2022 at 08:35 UTC
Updated:
22 Aug 2024 at 17:14 UTC
Jump to comment: Most recent
With the approach in #3034248: Promote use of Token Or module to make tokens more flexible it was possible to create a metatag value like this:
[node:field_hero_image:entity:field_media_image:og_image]||[site:base-url]/themes/custom/my_theme/image.png
Is this still possible with token_or?
Comments
Comment #2
jeroentComment #3
pianomansam commentedThis module doesn't offer that feature currently, but you're welcome to contribute it!
Comment #4
mxwright commented@JeroenT as is pointed out in the module description, custom URLs or strings can be added by using quotes. I would assume something like this would work for you without the base-url token:
[node:field_hero_image:entity:field_media_image:og_image]|"/themes/custom/my_theme/image.png"]Comment #5
jeroent@mxwright,
That's not exactly what I'm trying.
When you have a multisite or language negotation based on a domain and you want to use a token for e.g. the og:image (since that should be an absolute URL), the solution in #3034248: Promote use of Token Or module to make tokens more flexible supported something like this:
so the last part is a concatenation of a token and a string.
Anyway, since in my case it was language negotiation, I could work around this problem by translating the metatag config, but I think this is still a nice feature.
Comment #6
pianomansam commented@JeroenT what's complicated about your feature request is that it involves supporting tokens within tokens. That's not trivial. That can easily run into issues like infinite loops. I haven't seen any other module attempt that ability. If you have seen that somewhere, please let me know so I can evaluate how it can be done.
Comment #7
captain hindsight commentedThought about the same but in a different way.
For the example above
why not extend it like that:
I think this could be achieved by adding another condition in TokenOrTokensPreAlter::tokensPreAlter:
Comment #8
pianomansam commented@captain hindsight I think your solution could work. Feel free to create an issue fork to test that out.
Comment #9
zipme_hkt commented@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.
Comment #10
captain hindsight commentedThanks, 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` ?
Comment #11
pianomansam commented@captain hindsight Always open to pull requests!