Newer
Older
Alex Pott
committed
<?php
namespace Drupal\Core\Entity;
/**
Alex Pott
committed
* Provides an implementation of a content entity type and its metadata.
Alex Pott
committed
*/
class ContentEntityType extends EntityType implements ContentEntityTypeInterface {
Alex Pott
committed
/**
* An array of entity revision metadata keys.
*
* @var array
*/
protected $revision_metadata_keys = [];
Alex Pott
committed
/**
* {@inheritdoc}
*/
Alex Pott
committed
public function __construct($definition) {
parent::__construct($definition);
Alex Bronstein
committed
$this->handlers += [
catch
committed
'storage' => 'Drupal\Core\Entity\Sql\SqlContentEntityStorage',
'view_builder' => 'Drupal\Core\Entity\EntityViewBuilder',
];
Alex Bronstein
committed
$this->revision_metadata_keys += [
'revision_default' => 'revision_default',
];
Alex Pott
committed
}
Angie Byron
committed
/**
* {@inheritdoc}
*/
public function getConfigDependencyKey() {
return 'content';
}
Alex Bronstein
committed
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
* If the provided class does not implement
* \Drupal\Core\Entity\ContentEntityStorageInterface.
*
* @see \Drupal\Core\Entity\ContentEntityStorageInterface
Alex Bronstein
committed
*/
protected function checkStorageClass($class) {
$required_interface = ContentEntityStorageInterface::class;
if (!is_subclass_of($class, $required_interface)) {
throw new \InvalidArgumentException("$class does not implement $required_interface");
}
}
/**
* {@inheritdoc}
*/
public function getRevisionMetadataKeys() {
return $this->revision_metadata_keys;
}
/**
* {@inheritdoc}
*/
public function getRevisionMetadataKey($key) {
$keys = $this->getRevisionMetadataKeys();
return $keys[$key] ?? FALSE;
}
/**
* {@inheritdoc}
*/
public function hasRevisionMetadataKey($key) {
$keys = $this->getRevisionMetadataKeys();
return isset($keys[$key]);
}
/**
* {@inheritdoc}
*/
public function setRevisionMetadataKey($key, $field_name) {
if ($field_name !== NULL) {
$this->revision_metadata_keys[$key] = $field_name;
}
else {
unset($this->revision_metadata_keys[$key]);
}
return $this;
}