2

I need to be able to distinguish when entries for multilingual websites were last updated. If I use entry -> dateUpdated, it gives me the same date for the English and German version of the entry, even if I have only changed it in one language. Does anyone know if I can distinguish this and if so, how?

1 Answer 1

3

Craft does not keep track of the dateUpdated timestamp (or revision history in general) per site. You don't mention the actual use case, but regardless – you're not going to be able to use the native dateUpdated attribute for what you're trying to achieve.

Your only option is to keep track of the per-site update timestamp yourself, via some sort of custom field. I can think of at least 3 ways to do that:

  1. By far the simplest solution is to create a custom Date field. Make the field translatable per site, and instruct authors to manually update this field whenever they publish changes to entries.

  2. You can install the Preparse plugin, and create a custom Preparse date field. Preparse fields can be configured with simple, inline Twig templates that are rendered whenever the element is saved; the rendered value being automatically stored as a regular custom field value.

Set the field's "Column Type" setting to "Date (datetime)", and again - make it translatable per site. Then, add something like this to the field's "Twig code to parse" setting:

{{ now|date('Y-m-d H:i:s') }}

⚠️ Note that the Preparse plugin is not available for Craft 5 yet.

  1. Create a custom Yii module that saves the current date/time, per site... somewhere, whenever the relevant entries are saved. Custom modules are a huge topic, but some pointers:
  • Your module would need to add an event listener listening for the proper element event (likely Entry::EVENT_BEFORE_SAVE), to "capture" the entries as they are being saved.

  • In your event listener, you need to save the current date/time somewhere. The easiest option would probably be to create a Date field (again, make the field translatable by site), and set it like so:

...
$entry->setFieldValue('dateUpdatedCustomField', (new \DateTime())->format('Y-m-d H:i:s');
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.