Skip to content

Instantly share code, notes, and snippets.

@plach79
Created January 16, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plach79/f22ceca27c8d071464f46e46d5769f24 to your computer and use it in GitHub Desktop.
Save plach79/f22ceca27c8d071464f46e46d5769f24 to your computer and use it in GitHub Desktop.
<?php
/**
* {@inheritdoc}
*/
public function __construct($definition) {
// Only new instances should provide the required revision metadata keys.
// The cached instances should return only what already has been stored
// under the property $revision_metadata_keys.
$this->requiredRevisionMetadataKeys += [
'revision_default' => 'revision_default',
];
// Move stuff so blah blah blah
foreach ($this->requiredRevisionMetadataKeys as $key) {
if (isset($definition['revision_metadata_keys'][$key])) {
$this->requiredRevisionMetadataKeys[$key] = $definition['revision_metadata_keys'][$key];
unset($definition['revision_metadata_keys'][$key]);
}
}
parent::__construct($definition);
$this->handlers += [
'storage' => 'Drupal\Core\Entity\Sql\SqlContentEntityStorage',
'view_builder' => 'Drupal\Core\Entity\EntityViewBuilder',
];
// Add the required revision metadata fields here instead in the getter
// method, so that they are serialized as part of the object even if the
// getter method doesn't get called, which allows us to further extend the
// list and let only new instances of the class to contain the new list
// while the cached instances contain the previous version of the list.
$this->revision_metadata_keys += $this->requiredRevisionMetadataKeys;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment