You are here

public function DoubleField::isEmpty in Double Field 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldType/DoubleField.php \Drupal\double_field\Plugin\Field\FieldType\DoubleField::isEmpty()

Determines whether the data structure is empty.

Return value

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

Overrides Map::isEmpty

File

src/Plugin/Field/FieldType/DoubleField.php, line 451

Class

DoubleField
Plugin implementation of the 'double_field' field type.

Namespace

Drupal\double_field\Plugin\Field\FieldType

Code

public function isEmpty() : bool {
  $settings = $this
    ->getSettings();
  foreach ([
    'first',
    'second',
  ] as $subfield) {
    if ($settings['storage'][$subfield]['type'] == 'boolean') {

      // Booleans can be 1 or 0.
      if ($this->{$subfield} == 1) {
        return FALSE;
      }
    }
    elseif ($this->{$subfield} !== NULL && $this->{$subfield} !== '') {
      return FALSE;
    }
  }
  return TRUE;
}