You are here

public function EntityReferenceItem::hasNewEntity in Drupal 9

Same name and namespace in other branches
  1. 8 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()

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