You are here

public function EntityReferenceItem::isEmpty 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::isEmpty()

Determines whether the data structure is empty.

Return value

bool TRUE if the data structure is empty, FALSE otherwise.

Overrides Map::isEmpty

2 calls to EntityReferenceItem::isEmpty()
EntityReferenceItem::hasNewEntity in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
Determines whether the item holds an unsaved entity.
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 249

Class

EntityReferenceItem
Defines the 'entity_reference' entity field type.

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

Code

public function isEmpty() {

  // Avoid loading the entity by first checking the 'target_id'.
  if ($this->target_id !== NULL) {
    return FALSE;
  }
  if ($this->entity && $this->entity instanceof EntityInterface) {
    return FALSE;
  }
  return TRUE;
}