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

KarenS’s picture

Category: bug » feature
Status: Active » Postponed (maintainer needs more info)

This 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.

casey’s picture

Status: Active » Postponed (maintainer needs more info)

date_field_presave()? It seems to work for auto_nodetitle at least.

/**
 * Implements hook_field_insert().
 */
function date_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
  date_field_update_helper($entity_type, $entity, $field, $instance, $langcode, $items);
}

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.

KarenS’s picture

Status: Postponed (maintainer needs more info) » Active

Hmm, ok hook_field_presave(). Have you tried it? Do tests pass if you make that change?

casey’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Hmm 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.

KarenS’s picture

Status: Closed (works as designed) » Fixed

Actually 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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.