public function ComputedFieldItem::isEmpty in Computed Field 8
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/ ComputedFieldItem.php, line 194
Class
- ComputedFieldItem
- Plugin implementation of the 'computed' field type.
Namespace
Drupal\computed_field\Plugin\Field\FieldTypeCode
public function isEmpty() {
$value = $this
->get('value')
->getValue();
$data_type = $this
->getSetting('data_type');
$empty = TRUE;
// This will depend on the class of data type.
switch ($data_type) {
case 'int':
case 'float':
case 'numeric':
// For numbers, the field is empty if the value isn't numeric.
$empty = $value === NULL || !is_numeric($value);
break;
case 'varchar':
case 'text':
case 'longtext':
// For strings, the field is empty if it doesn't match the empty string.
$empty = $value === NULL || $value === '';
break;
}
return $empty;
}