ContentEntityType.php in Drupal 8
File
core/lib/Drupal/Core/Entity/ContentEntityType.php
View source
<?php
namespace Drupal\Core\Entity;
class ContentEntityType extends EntityType implements ContentEntityTypeInterface {
protected $revision_metadata_keys = [];
protected $requiredRevisionMetadataKeys = [];
public function __construct($definition) {
parent::__construct($definition);
$this->handlers += [
'storage' => 'Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage',
'view_builder' => 'Drupal\\Core\\Entity\\EntityViewBuilder',
];
if (!isset($this->revision_metadata_keys['revision_default'])) {
$this->requiredRevisionMetadataKeys['revision_default'] = 'revision_default';
}
$this->revision_metadata_keys += $this->requiredRevisionMetadataKeys;
}
public function getConfigDependencyKey() {
return 'content';
}
protected function checkStorageClass($class) {
$required_interface = ContentEntityStorageInterface::class;
if (!is_subclass_of($class, $required_interface)) {
throw new \InvalidArgumentException("{$class} does not implement {$required_interface}");
}
}
public function getRevisionMetadataKeys($include_backwards_compatibility_field_names = TRUE) {
if ((!$this->revision_metadata_keys || $this->revision_metadata_keys == $this->requiredRevisionMetadataKeys) && $include_backwards_compatibility_field_names) {
$base_fields = \Drupal::service('entity_field.manager')
->getBaseFieldDefinitions($this
->id());
if (isset($base_fields['revision_uid']) && ($revision_user = 'revision_uid') || isset($base_fields['revision_user']) && ($revision_user = 'revision_user')) {
@trigger_error('The revision_user revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_user'] = $revision_user;
}
if (isset($base_fields['revision_timestamp']) && ($revision_timestamp = 'revision_timestamp') || isset($base_fields['revision_created']) && ($revision_timestamp = 'revision_created')) {
@trigger_error('The revision_created revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_created'] = $revision_timestamp;
}
if (isset($base_fields['revision_log']) && ($revision_log = 'revision_log') || isset($base_fields['revision_log_message']) && ($revision_log = 'revision_log_message')) {
@trigger_error('The revision_log_message revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_log_message'] = $revision_log;
}
}
return $this->revision_metadata_keys;
}
public function getRevisionMetadataKey($key) {
$keys = $this
->getRevisionMetadataKeys();
return isset($keys[$key]) ? $keys[$key] : FALSE;
}
public function hasRevisionMetadataKey($key) {
$keys = $this
->getRevisionMetadataKeys();
return isset($keys[$key]);
}
public function setRevisionMetadataKey($key, $field_name) {
if ($field_name !== NULL) {
$this->requiredRevisionMetadataKeys[$key] = $field_name;
$this->revision_metadata_keys[$key] = $field_name;
}
else {
unset($this->requiredRevisionMetadataKeys[$key], $this->revision_metadata_keys[$key]);
}
return $this;
}
}