3 namespace Drupal\entity_reference_revisions\TypedData;
5 use Drupal\Core\Entity\TypedData\EntityDataDefinition;
6 use Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface;
9 * A typed data definition class for describing entities.
11 class EntityRevisionDataDefinition extends EntityDataDefinition implements EntityDataDefinitionInterface {
16 public static function createFromDataType($data_type) {
17 $parts = explode(':', $data_type);
18 if ($parts[0] != 'entity_revision') {
19 throw new \InvalidArgumentException('Data type must be in the form of "entity_revision:ENTITY_TYPE:BUNDLE."');
21 $definition = static::create();
22 // Set the passed entity type and bundle.
23 if (isset($parts[1])) {
24 $definition->setEntityTypeId($parts[1]);
26 if (isset($parts[2])) {
27 $definition->setBundles(array($parts[2]));
35 public function getDataType() {
36 $type = 'entity_revision';
37 if ($entity_type = $this->getEntityTypeId()) {
38 $type .= ':' . $entity_type;
39 // Append the bundle only if we know it for sure and it is not the default
41 if (($bundles = $this->getBundles()) && count($bundles) == 1) {
42 $bundle = reset($bundles);
43 if ($bundle != $entity_type) {
44 $type .= ':' . $bundle;