You are here

public function FileUrlItem::isEmpty in File URL 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldType/FileUrlItem.php \Drupal\file_url\Plugin\Field\FieldType\FileUrlItem::isEmpty()

Determines whether the data structure is empty.

Return value

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

Overrides EntityReferenceItem::isEmpty

File

src/Plugin/Field/FieldType/FileUrlItem.php, line 66

Class

FileUrlItem
Plugin implementation of the 'file_url' field type.

Namespace

Drupal\file_url\Plugin\Field\FieldType

Code

public function isEmpty() {
  $is_empty = parent::isEmpty();

  // An entity reference item is empty when the target ID is strictly NULL in
  // order to allow pointing to 0 (integer zero) or '' (empty string). That
  // makes sense if you think that a user reference can point to Anonymous
  // user (uid === 0) or a taxonomy term points to the root (tid === 0). But
  // an file_url item is empty when the target ID is '' (empty string).
  if (!$is_empty && is_string($this->target_id)) {
    $target_id = trim($this->target_id);
    if ($target_id === '') {
      return TRUE;
    }
  }
  return $is_empty;
}