function EntityReferenceItem::hasNewEntity

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::hasNewEntity()
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::hasNewEntity()
  3. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::hasNewEntity()

Determines whether the item holds an unsaved entity.

This is notably used for "autocreate" widgets, and more generally to support referencing freshly created entities (they will get saved automatically as the hosting entity gets saved).

Return value

bool TRUE if the item holds an unsaved entity.

2 calls to EntityReferenceItem::hasNewEntity()
EntityReferenceItem::getValue in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
Gets the data value.
EntityReferenceItem::preSave in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
Defines custom presave behavior for field values.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php, line 476

Class

EntityReferenceItem
Defines the 'entity_reference' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public function hasNewEntity() {
    return !$this->isEmpty() && $this->target_id === NULL && $this->entity
        ->isNew();
}

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