Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support old hyphenated tokens (field-tags) in addition to current underscored (field_tags) #144

Open
bugfolder opened this issue Jan 22, 2022 · 8 comments

Comments

@bugfolder
Copy link
Collaborator

Many tokens that were hyphenated in Drupal 7 are now underscored in Backdrop, e.g., field-tags is now field_tags. For Rules imported from D7, the old-style tokens will no longer render. Users will need to update their Rules.

Things we could consider doing to help them out:

  • Detect old-style tokens and warn them about it during upgrade;
  • Automatically handle old-style tokens, but post a deprecated-token warning in watchdog;
  • Automatically change any old-style tokens (but that would require overriding any rules with old-style tokens that exist in code)
@argiepiano
Copy link
Collaborator

To clarify, not all tokens in Backdrop use underscores. Only tokens of Field API fields do. D7 Entity Tokens used to provide a second token for each field that was dashed. This was changed in Backdrop's port of Entity Tokens to match the core's field tokens, which use underscore (NB: field tokens provided in core are pretty limited and can't be chained, which is why Entity Tokens is still needed with Rules).

Your No. 2 option above is better done in Entity Tokens rather than in Rules, since Rules simply invokes token_replace() for tokens entered in the Direct input or Value textareas. This is actually in my todo list for Entity Tokens and I will welcome help and testing.

@argiepiano
Copy link
Collaborator

The latest release of Entity Tokens (1.x-2.0.0-rc1) now supports hyphenated field tokens (both chained or unchained, as in [node:field-tags] and [node:field-tags:0]).

This means that these tokens are also available to Rules in Direct Input text areas.

However, since underscores are still the "official" pattern supported in core, the token list shown in "Replacement patterns" still shows only the ones with underscores, i.e. [node:field_tags:0] etc. But the ones with dashes will be fulfilled, which improves compatibility with D7 Rules when imported.

Posting deprecated watchdog messages was too complicated for Entity Tokens to handle, since it's unclear whether a token is really deprecated. Dashes are still legit (not deprecated) in certain core tokens like [node:comment-count]. Therefore throwing a notice for that would actually be incorrect. Tokens are fulfilled in different places (by hook_tokens in several modules), and it's impossible for one implementation of that hook to "know" whether another one has fulfilled a legit token with dashes. And, a bogus token like [node:field-bogus] may throw a deprecated notice, while in fact the real problem is that it doesn't exist.

@keiserjb
Copy link

keiserjb commented Aug 26, 2022

I'm confused about trying to access an image field. In D7 I could use [node:field-image:file:url]. I try that in Backdrop and I get an empty email(my rules action is send an html email). Interestingly it works when I use data selection input node:field-image:file:url. Having that gives me the url in an email. But when I go back to direct input it no longer works.

I'm wanting to do this sort of thing in the HTML body but the image is always missing in Backdrop.
<p>[node:body]</p> <img src="[node:field-image:file:url]" />

@argiepiano
Copy link
Collaborator

There are several parts to my answer:

  1. Unlike D7 (when Entity Tokens was installed), field tokens in Backdrop now use low hyphens. So you need [node:field_image....
  2. In D7, the token you pasted was provided by Entity Tokens. In Backdrop, Entity Tokens skips all image field tokens, because they are now provided by core in Backdrop. Therefore the syntax is different
  3. I suggest you install Token Help, which will tell you exactly the syntax of the token you need.
  4. The "data selection" widget in Rules doesn't use tokens, but rather "faux tokens" that have kept the syntax from Drupal's Entity Token. Those "faux tokens" will not work if you type them using the "Direct input" widget in Rules - you need to enter tokens using the new syntax.

In Backdrop core, image tokens require the style. So your token will look something like (note the low hyphen):

[node:field_image:medium:path]

This will give you the path for the "medium" style. Replace with needed style.

I hope that helps...

@argiepiano
Copy link
Collaborator

argiepiano commented Aug 27, 2022

I need to clarify that Backdrop Entity Tokens now provide the option of using regular hyphens (as in field-image), BUT (important BUT), image field tokens are NOT fulfilled by Entity Tokens in Backdrop, since they are now provided by Backdrop's core. Therefore the hyphen syntax will not work for image fields.

I know, it's confusing, but the token replacement API is pretty primitive in Backdrop/Drupal, and the fact that SOME field tokens from the D7 contrib Token were integrated into core in Backdrop (as patch work), did not help. I was forced to completely skip image field tokens in Entity Tokens to prevent errors.

@keiserjb
Copy link

I'm still not getting the actual image. Now I get a link to the image style.

@argiepiano
Copy link
Collaborator

How about we look at this during office hours?

@keiserjb
Copy link

How about we look at this during office hours?

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants