Created
January 16, 2018 22:29
-
-
Save plach79/f22ceca27c8d071464f46e46d5769f24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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