Hi guys,

Thanks very much for the great work on this Drupal 7 version of the module, it certainly provides a very useful function.

We have surely been following with a lot of interest the evolution of the module with its 7.x-1.x version.

I would like to get back quickly on a particular aspect of the implementation of the Drupal 7 port, in particular, related with a comment from @james.williams, at #1053402-17: ImageField tokens D7 version:

Also, I would like to change the timing of the token replacements from on node/field saving, to when they should be displayed (since the tokens values could change between those times), but for now I'm just sticking with how it was previously implemented.

who also posted patches in the same ticket and especially the one at #1053402-19: ImageField tokens D7 version:

the token replacement happens when the field is attached for display, rather than on saving the node (entity) so they can be more dynamic.

Corresponding patch: imagefield_tokens-better-D7-port-1053402-19.patch.

Then @eosrei's comment with the sandbox version came in at #1053402-33: ImageField tokens D7 version and unfortunately @james.williams's version wasn't discussed any further afterwards.

I wanted to get back and try to bring your attention on a specific aspect of his suggested implementation:

<?php
/** 
 * Implementation of hook_field_attach_view_alter().
 */
function imagefield_tokens_field_attach_view_alter(&$output, $context) {
...
}
?>

I may have missed something in the whole discussion process, but after looking in the tracker, I couldn't find any answer to the following question:
 
Was there any particular reason why the implementation of imagefield_tokens_field_attach_presave would be chosen over imagefield_tokens_field_attach_view_alter?

Ultimately ending in an important difference:

  • imagefield_tokens_field_attach_presave: tokens for alt and title attributes are evaluated upon node/entity save, not on the fly.
  • imagefield_tokens_field_attach_view_alter: tokens for alt and title attributes are evaluated on the fly, not stored.

I would assume using imagefield_tokens_field_attach_presave (in current module's implementation) and saving evaluated values could present certain problems in the long run if external objects were referenced with related token values. For example, taxonomy term names, user names, product prices, etc...
For E-Commerce sites, for example, if the price from a related product had to be displayed in alt and title attributes, there are great chances that this information might change quite often if there are discounts to evaluate.

I would guess each one of these implementation choices could have advantages and drawbacks, but for my information, I would be greatly interested in finding out if there would be any particular reason why imagefield_tokens_field_attach_view_alter would not be considered for this module's code.
Perhaps not enough attention was brought to the intial patches from @james.williams, more particularly the one at #1053402-19: ImageField tokens D7 version.

I would greatly appreciate to have your feedback on this alternate approach and if you could let me know if I overlooked or missed anything in current module's implementation or Drupal API in general.

Feel free to let me know if you would have any questions, comments or concerns about any aspect of the discussed implementation, I would be glad to explain in more details.

Thanks very much to all, in advance, for your comments, feedback, and support.
Cheers!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DYdave’s picture

Quick follow up on this ticket.

After doing quite a few tests, with Commerce Product Reference, Taxonomy Terms, Users or Entity Reference, I came up with the following patch against latest imagefield_tokens-7.x-1.x-dev (2013-01-04), attached to this ticket as:
imagefield_tokens-alternate-approach-replacement-on-the-fly-1934986-1.patch

Please find below a detailed log of the changes:

Detailed log:

In general, this patch is greatly inspired from the patch posted by @james.williams at #1053402-19: ImageField tokens D7 version:

1 - Major change: Removed imagefield_tokens_field_attach_presave and replaced with imagefield_tokens_field_attach_view_alter
Added implementation of hook_field_attach_view_alter, based on initial patch, modified to reduce slightly the code and added inline comments.
The main difference mostly relies in the call to token_replace when the field is being assembled to be displayed. Since token patterns are replaced on the fly, there is no need to store them with an implementation of hook_field_attach_presave, thus removed from code.

2 - Removed alt_field_update_on_edit and title_field_update_on_edit
Since evaluated token values are not stored anymore, but replaced when field is viewed, there is no need to keep the settings or the logic related to update values on edit or storing values.

3 - Code clean-up
Added Doc block comments, inline comments and fixed a few minor coding standard issues.
Added support to Token (dialog) browser UI (since Token 7.x-1.2, for more information see #1872692: Provide support for Token UI browser)

This patch has been thoroughly tested for a while already and seems to work as expected.
(Tested with Features, Internationalization, Entity Translation, Drupal Commerce, Entity Reference, and several other modules, without any conflicts or issues)

If you think the proposed implementation attached would help improving the module and you would consider this feature request as acceptable, I would certainly be glad to discuss further how this code/patch could be integrated to module's code base or any additional work that would contribute to improving the overall quality of the module, for example on documentation.
Another option would be to create another/new branch 7.x-2.x, for example, which would leave the choice to developers and users to choose a preferred structural implementation (features would be the same, with or without storage/replacement on the fly).
Another possibility would be to add a configuration setting to allow users to select whether replacements would have to be stored or take place when field is viewed (allowing both implementations to coexist, for example, by default, it could be a replacement at run-time).

Could you please let me know if I overlooked or missed anything in the current ImageField Tokens module, in terms of whether the approach is correct or not?

Please let me know if you would have any questions on any points/code/aspects mentioned in this ticket, I would surely be glad to provide more information.

I would greatly appreciate some help from module maintainers and if any of you could take a bit of time to look into the attached patch to give me your feedback/opinion on this feature request.

Any feedback, testing, changes, recommendations would be highly appreciated.
Thanks to all in advance.

13rac1’s picture

DYDave, thanks for one of the most detailed d.o. issues I've ever seen.

I implemented using hook_field_attach_presave , because the original 6.x module also implemented during save and I didn't want to change to the expected functionality of the module. I like this idea and your patch even solves a couple of the 7.x-1.0 release blockers. The only problem I see is the functionality change. I'd prefer a functionality addition. There are already 450+ sites using the 7.x of the module. We can't know exactly how they are using it, and whether they are relying on the save aspect of the current implementation.

Since "evaluate on save" functionality already exists, it should stay as the default. A radio button on the content type form could allow the site builder to select between the two options.

Evaluate alt/title Tokens on:
* Save
* View

DYdave’s picture

Hi eosrei,

Thanks a lot for your prompt feedback and I'm glad you appreciated the detailed description and ticket.
I'm really happy to see that you would be able to consider this feature request as acceptable and that you would be open to a dialog.

I certainly understand your concerns about compatibility and updating the sites that would be using the current implementation.

I think we could perhaps approach the problem from the following angle:

First of all, I can understand better your initial implementation of hook_field_attach_presave which was probably the closest to a direct Port to D7 of the D6 module and features.
Since hook_field_attach_view_alter was only introduced in Drupal 7 and doesn't exist for Drupal 6, then it could be considered as a new implementation or feature with no backward compatibility (couldn't be ported to D6).

Then it comes down to Drupal 7 with the following possibilities:
a. Creating a new branch (7.x-2.x, for example) would sound perfectly legitimate/reasonable since we could consider the 7.x-1.x branch as a direct port from the 6.x-1.x branch, and 7.x-2.x would be more specific to the Drupal 7 API. The new branch would only keep a single main implementation (based on the most recent hooks/API), in particular, hook_field_attach_view_alter, or at least set the previous implementation as deprecated in the sense that the settings could still be configured but wouldn't be selected by default.
In this case, we could think of adding an implementation of hook_update to the patch for updates of earlier versions.

b. Adding the feature to the existing 7.x-1.x, with the following issues:
- alt_field_update_on_edit and title_field_update_on_edit wouldn't necessarily be useful in the case "View" would be selected.
(We could add a few more JS states '#states' here and there on radios/checkboxes to hide/display)

- Selecting a default: "Save".
I would like to disagree with that: I think an update with the patch (hook_update) could set all existing fields configurations values to "Save", so that nothing changes on update for existing sites.
However, I would personally think that for any new field or configuration added, the default value would have to be "View".
(The idea behind this, would be trying to move forward towards using newer API hooks implementations - hook_field_attach_view_alter).

I would greatly appreciate your feedback on this comment and how you would think we could approach the integration of this feature to the module in the smoothest way.

Feel free to let me know if you would have any questions, comments, issues, objections, recommendations, suggestions or further concerns on any aspects of this feature request, my comment or the attached patch, I would be glad to provide more information, explain in more details or re-roll the patch if necessary.

Any comments, testing, reporting, feedback, reviews or questions would be highly appreciated
Thanks to all in advance for your comments, reviews and replies.
Cheers!

DYdave’s picture

Hi eosrei,

Quick follow-up on this issue:
Since it has already been a little bit more than two weeks without getting any updates on this ticket (see #3 on March 6, 2013), feedback or comments on my latest reply, I was wondering if you had enough time to consider the approaches suggested in #3.

I would greatly appreciate to hear your feedback, questions, comments, concerns or replies on any aspects mentioned above, I would certainly be glad to help improving the patch or module in general.

Once again, any comments, testing, reporting, feedback, reviews or questions would be highly appreciated.
Thanks to all in advance for your comments, reviews and replies.
Cheers!

13rac1’s picture

DyDave, I can look into further changes to this later next week.

DYdave’s picture

Priority: Normal » Major

Hi eosrei,

Thanks again for your kind and prompt answer.

Yet another attempt to follow-up on this issue:
Two more weeks have passed, without getting any updates on this ticket (see #5 on March 21, 2013), feedback, comments or replies to my successive follow-ups, I was wondering if you had enough time to consider the approaches suggested in #3.

Changing priority to Major as an attempt to get more attention from maintainers and other developers.

I would greatly appreciate to hear your feedback, questions, comments, concerns or replies on any aspects mentioned above, I would certainly be glad to help improving the patch or module in general.

Lastly, if this could help on the communication side, feel free to contact me directly at anytime on IRC, perhaps this could help speeding up the discussion process and save some of your time.

Once again, any comments, testing, reporting, feedback, reviews or questions would be highly appreciated.
Thanks to all in advance for your comments, reviews and replies.
Cheers!

13rac1’s picture

Priority: Major » Normal
Status: Needs review » Needs work

Back to Normal, Priority is not for attention and almost never for feature requests.

I'm not sure I understand how "tokens on the fly" is more specific to D7 then "tokens on save" both implementations only use functionality available in D7.

I'd prefer not to deprecate the original functionality. Please make a patch against 7.x-1.x-dev to add this functionality, changing the default and including an update hook is acceptable.

Thanks for your effort/work!

jasom’s picture

Which token should I use for referenced product of drupal commerce?

Product is referencing to content type product_display (alt and title fields are in product, not in content type). Only token which worked was [current-page:title] (It created token like "EDIT product title name"). Tokens witch didn't work with current D7 dev:
[node:title]
[node:field-product]
[node:field-product:1]
[node:field-product:1:field-product-node]
[node:field-product:1:commerce-product-commerce-line-item]
[node:field-product:1:title]
[node:original:title]

csc4’s picture

Seems a great shame this isn't in the module, had to reluctantly stop using it as it is failing to replace tokens with values.

Jose Reyero’s picture

@DYdave, thanks
I've been testing this patch, it still applies and works fine. This is also the behavior I would expect from this module.

However, I think @eosrei #2 has a point about the need to keep current -original- behavior as a default, because with this patch the module is somehow different and it may cause trouble with current users of the module.

If there's still any interest in maintaining this module I may take care of re-rolling the patch with the required options mentioned by @eosrei in #2 so it is backwards compatible while implementing this new behavior. Please let me know.

Jose Reyero’s picture

Attached a new patch (with diff) with a minor change: it cleans up tokens when not replaced.

ciss’s picture

Status: Needs work » Needs review
NWOM’s picture

Status: Needs review » Needs work

#11 applies great. However, as explained in #2 there are certain sites that require it to be optional without breaking the functionality on upgrade.

Sadly in my case, it breaks alt tags from auto-filling the caption when in combination with the Views jQFX Imageflow module as an example.