I have an entity class where some entity properties are implemented as protected properties and are accessed through the __get
and __set
magic methods. It is works with every other part of the entity API, but as I enabled revision support for this entity, I noticed that these special properties are not written to the revision table, just the base table.
I think the cause is the following code in EntityAPIController::saveRevision()
:
// Convert the entity into an array as it might not have the same properties
// as the entity, it is just a raw structure.
$record = (array) $entity;
When converting to an array, the __get
magic method is ignored, and the protected storage properties are copied into $record
with special names: "\0*\0propertyname". I do not understand the point of converting to array, even though it has a short explanation. drupal_write_record
is used to save the revision, which casts $record
to object, so it becomes an stdClass
.