Problem/Motivation
Entity keys tell you how to get the common fields of different entity types that might have different specific field names. E.g. 'created', 'published', 'author'.
Entities which implement EntityChangedInterface are expected to have a field to store the changed timestamp, but there's no way to find out what that field is.
This affects code which needs to work at the field level rather than use the interface methods -- e.g. using JSONAPI data.
Steps to reproduce
Proposed resolution
Add a 'changed' entity key to core entity types which implement EntityChangedInterface.
- In the Drupal code base, lookup all content entity types that have EntityChangedInterface implemented.
- Per entity type, find out how the field is called that stores the changed timestamp.
- Define the new key in the annotation of the entity class, for example if the field is called "foo":
* entity_keys = { (...) * "changed" = "foo", * },
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3549707
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
megachrizThe Drupal Contribution Mentoring team is triaging issues for DrupalCon Vienna 2025, and we are reserving this issue for Mentored Contribution during the event.
After October 17, this issue returns to being open to all. Thanks!
I also updated the issue summary with the list of steps to resolve the issue.
Comment #3
joachim commentedComment #4
robbertnl commentedI am working on this #vienna2025 during mentored contribution with @megachriz
Comment #6
robbertnl commentedI added the changed field to entity_keys but now the test pipeline is failing. This still needs to be fixed by someone.
Comment #7
joachim commentedWow, that's some impressive test failures!
AFAIK nothing is looking for the 'changed' entity key, since, again AFAIK, we're inventing it in this MR. And yet, things fall over dramatically:
> ├ SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'changed' cannot be null: INSERT INTO "test36480953taxonomy_term_field_data" ("tid", "revision_id", "vid", "langcode", "status", "name", "description__value", "description__format", "weight", "changed", "default_langcode", "revision_translation_affected") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array
Comment #8
joachim commentedI can't reproduce the test failure locally -- this gets in the way: #3552984: MigrateTestBase::display() causes a TypeError if a test fails a migration.
Comment #9
joachim commentedOk I can confirm that with the MR, the 'changed' field on taxonomy terms doesn't get an ALLOW NULL, and without the MR, it does.
I have NO idea how!!!
Comment #10
joachim commentedFound it:
Urgghh. Spooky side-effects FTL :(
We probably need to add 'changed' to the keys that are unset here.