InventoryItem.php in farmOS 2.x
File
modules/core/inventory/src/Plugin/Field/FieldType/InventoryItem.php
View source
<?php
namespace Drupal\farm_inventory\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
class InventoryItem extends FieldItemBase {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'measure' => [
'description' => 'Measure of the inventory',
'type' => 'varchar',
'length' => 32,
],
'value' => [
'description' => 'Value of the inventory',
'type' => 'varchar',
'length' => 32,
],
'units' => [
'description' => 'Units of the inventory',
'type' => 'varchar',
'length' => 128,
],
],
];
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['measure'] = DataDefinition::create('string')
->setLabel(t('Measure of the inventory'));
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Value of the inventory'));
$properties['units'] = DataDefinition::create('string')
->setLabel(t('Units of the inventory'));
return $properties;
}
public function isEmpty() {
return ($this->measure === NULL || $this->measure === '') && ($this->value === NULL || $this->value === '') && ($this->units === NULL || $this->units === '');
}
}