Move entity preparation from form controller to entity class: "last changed" timestamp not updated and "create new revision" setting not respected when updating entities via Entity API

Created on 10 December 2012, over 12 years ago
Updated 10 February 2025, 3 months ago

Problem/Motivation

While an entity type's form controller class might be the primary form by which to edit an entity, it should be possible to create additional forms: for example, an in-place editing form, as in #1824500: In-place editing for Fields . Also, entities can be edited outside of forms entirely, via RESTful web services, as in #1826688: REST module: PATCH/update .

What is currently done by \Drupal\Core\Entity\ContentEntityForm::buildEntity(), \Drupal\Core\Entity\ContentEntityForm::updateChangedTime() and friends has nothing to do with forms: it's just about doing further manipulation of $entity that wasn't done during entity object creation and entity loading for … legacy reasons?

The problem is that all these "things that should happen automatically when the entity is modified" only happen when the entity is modified via the entity edit form. But those things should also happen when:

  1. using in-place editing (proposed work-around: #2925846: Quick Edit only creates revision for Node entities, should do it for all content entity types that support it )
  2. using the core REST module (proposed work-around: #2838395: [PP-1] Entity API bug affecting REST: "last changed" timestamp not updated and "create new revision" setting not respected when PATCHing via REST )
  3. using the contrib JSON API module
  4. using the contrib GraphQL module

Proposed resolution

Move this logic to the entity classes themselves, or wherever appropriate. Basically, the following should happen automatically at entity save time:

  1. if the entity is revisionable, and it has a bundle entity type which implements \Drupal\Core\Entity\RevisionableEntityBundleInterface, respect the setting stored in the bundle entity
  2. if the entity has a new revision, automatically set the revision creation time
  3. if the entity is being created in a request where a user is authenticated, that user should be the author of the revision
  4. if the entity implements EntityChangedInterface, set the updated time

Remaining tasks

  1. TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component

entity system

Created by

🇺🇸United States effulgentsia

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024