Several places in Field-related code need to know if a object update is creating a new revision.
- file field's implementation of hook_field_update()
- patch RTBC in #629252: field_attach_form() should make available all field translations on submit
The code currently hardcodes a check on $object->revision.
2 options:
1) Nodes being the only 'revisionable' entity so far, we do have the latitude to state that the 'revision' property has a fixed conventional meaning, and that entity types with revisions need to make sure $object->revision is TRUE when a new revision is being saved.
If so, this needs to be documented - in hook_entity_info() ?
2) Like we do for 'properties with legacy' (object id = nid, uid, cid, tid...), we ask entity types to declare the name of the property with the 'new revision' semantic, through hook_entity_info()'s 'object keys' entry.
'object keys' being a way to workaround legacy differences that I still kind of hope we'll be able to attenuate in a D8 iteration of the entity API, I'd tend to lean towards 1) and not add another abstraction where it's not strictly needed.
No strong bias, though, opinions welcome.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | drupal.entity-revision.5.patch | 1.84 KB | sun |
Comments
Comment #1
yched commentedbumping out of the 'Field API' bucket.
Comment #2
damien tournoud commentedI don't follow you here.
Let's take a step backward: SQL doesn't mandate any particular name for the primary key of a table, but that doesn't mean that the "concept" of a table is not abstracted. I don't see how letting each entity pick the names of those properties to match their own concept will make the entity API harder to implement.
Comment #3
yched commentedWell, having to go through code like
or
to work with any object property where you want generic semantics attached (id, bundle name, language...) is convoluted (euphemism).
Comment #4
plachI'm slightly in favor of a new object key, mainly for consinstency reasons.
If we decide to go this way, we should keep in mind that
Comment #5
sunWhatever we do, please continue from this patch. (@see http://api.drupal.org/api/function/entity_extract_ids/7)
Comment #6
catchsubscribing.
Comment #7
casey commentedWhile this isn't addressed in D7 I certainly hope any contrib module that implements revision-able entity types uses option 1 to indicate a entity will we saved as a new revision; that is using the $entity->revision key.
Comment #8
casey commentedAn $entity->age (ENTITY_CURRENT|ENTITY_REVISION) property would also be handy.
Comment #9
catchMoving to D8.
Comment #10
fagoI do think for D8 every entity should be based upon a class implementing the "EntityInterface", which provides some simple methods to easily access identifiers, revision ids, labels, uris as well as save(), delete(), .. methods.
So, while we would have simple access to something like the revision identifier then, I do still think that we might want to standardize things like the revision property name. If it's easy to unify things, it helps us to avoid needless abstraction.
Comment #11
plach@fago:
totally agreed
Comment #12
skwashd commentedsubscribing
Comment #13
berdirHave a look at #1723892: Support for revisions for entity save and delete operations, which adds revision CRUD support to the default storage controller and also adds a isNewRevision() method to EntityInterface. Haven't updated existing code yet, could be done here once that is in. Needs review :)
Comment #14
berdirClosing, entities have methods for this now.