Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It is currently impossible to alter entity properties (like node title) based on date fields. This because date_field_update_helper() is run during field_attach_insert/update().
For an example see: #1197278: Date tokens are not displaying correctly
Isn't it possible to call date_field_update_helper() in date_field_presave() instead of date_field_insert/update()?
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedThis is using hook_field_update() and hook_field_insert(). Those are the only hooks available from the field system. I don't know any other way to alter field information. If you think there is another way, you will have to figure out what it might be.
Comment #2
casey CreditAttribution: casey commenteddate_field_presave()? It seems to work for auto_nodetitle at least.
Not sure if you can remove the call to date_field_update_helper() from date_field_insert/update() then. Not sure what the consequenses are.
Comment #3
KarenS CreditAttribution: KarenS commentedHmm, ok hook_field_presave(). Have you tried it? Do tests pass if you make that change?
Comment #4
casey CreditAttribution: casey commentedHmm I found another fix for auto nodetitle. There are probably multiple other field types that don't have all their data available right after form submission.
I'd say this isn't a bug, and if it is, it's a core issue.
Comment #5
KarenS CreditAttribution: KarenS commentedActually it simplifies the code a bit and seems to work and pass tests to use the pre_save() hook instead of doing this in field_update() and field_insert(). So I'm going to make this change anyway.
http://drupalcode.org/project/date.git/commit/d856857