function EntityReference::isTargetNew

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php \Drupal\Core\Entity\Plugin\DataType\EntityReference::isTargetNew()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php \Drupal\Core\Entity\Plugin\DataType\EntityReference::isTargetNew()
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php \Drupal\Core\Entity\Plugin\DataType\EntityReference::isTargetNew()

Checks whether the target entity has not been saved yet.

Return value

bool TRUE if the entity is new, FALSE otherwise.

File

core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php, line 59

Class

EntityReference
Defines an 'entity_reference' data type.

Namespace

Drupal\Core\Entity\Plugin\DataType

Code

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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.