X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fmodules%2Fcontrib%2Fentity_reference_revisions%2Fsrc%2FPlugin%2FDataType%2FEntityReferenceRevisions.php;fp=web%2Fmodules%2Fcontrib%2Fentity_reference_revisions%2Fsrc%2FPlugin%2FDataType%2FEntityReferenceRevisions.php;h=0000000000000000000000000000000000000000;hb=059867c3f96750652c80f39e44c442a58c2549ee;hp=c9e66ac6656263e0517264bd43baff8285cd3528;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2;p=yaffs-website diff --git a/web/modules/contrib/entity_reference_revisions/src/Plugin/DataType/EntityReferenceRevisions.php b/web/modules/contrib/entity_reference_revisions/src/Plugin/DataType/EntityReferenceRevisions.php deleted file mode 100644 index c9e66ac66..000000000 --- a/web/modules/contrib/entity_reference_revisions/src/Plugin/DataType/EntityReferenceRevisions.php +++ /dev/null @@ -1,123 +0,0 @@ -addConstraint('Bundle', $bundle); - * \Drupal\Core\TypedData\DataReferenceDefinition::create('entity_revision') - * ->setTargetDefinition($definition); - * @endcode - * - * @DataType( - * id = "entity_revision_reference", - * label = @Translation("Entity reference revisions"), - * definition_class = "\Drupal\Core\TypedData\DataReferenceDefinition" - * ) - */ -class EntityReferenceRevisions extends EntityReference { - - /** - * The entity revision ID. - * - * @var integer|string - */ - protected $revision_id; - - /** - * The entity ID. - * - * @var integer|string - */ - protected $id; - - /** - * Returns the definition of the referenced entity. - * - * @return \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface - * The reference target's definition. - */ - public function getTargetDefinition() { - return $this->definition->getTargetDefinition(); - } - - /** - * Checks whether the target entity has not been saved yet. - * - * @return bool - * TRUE if the entity is new, FALSE otherwise. - */ - public function isTargetNew() { - // If only an ID is given, the reference cannot be a new entity. - return !isset($this->id) && isset($this->target) && $this->target->getValue()->isNew(); - } - - /** - * {@inheritdoc} - */ - public function getTarget() { - if (!isset($this->target) && isset($this->revision_id)) { - // If we have a valid reference, return the entity's TypedData adapter. - $entity = \Drupal::entityTypeManager()->getStorage($this->getTargetDefinition()->getEntityTypeId())->loadRevision($this->revision_id); - $this->target = isset($entity) ? $entity->getTypedData() : NULL; - } - return $this->target; - } - - /** - * {@inheritdoc} - */ - public function getTargetIdentifier() { - if (isset($this->id)) { - return $this->id; - } - elseif ($entity = $this->getValue()) { - return $entity->id(); - } - } - - /** - * {@inheritdoc} - */ - public function setValue($value, $notify = TRUE) { - unset($this->target); - unset($this->id); - unset($this->revision_id); - - // Both the entity ID and the entity object may be passed as value. The - // reference may also be unset by passing NULL as value. - if (!isset($value)) { - $this->target = NULL; - } - elseif (is_object($value) && $value instanceof EntityInterface) { - $this->target = $value->getTypedData(); - } - elseif (!is_scalar($value['target_id']) || !is_scalar($value['target_revision_id']) || $this->getTargetDefinition()->getEntityTypeId() === NULL) { - throw new \InvalidArgumentException('Value is not a valid entity.'); - } - else { - $this->id = $value['target_id']; - $this->revision_id = $value['target_revision_id']; - } - // Notify the parent of any changes. - if ($notify && isset($this->parent)) { - $this->parent->onChange($this->name); - } - } -}