You are here

public static function StockLevel::propertyDefinitions in Commerce Stock 8

Defines field item properties.

Properties that are required to constitute a valid, non-empty item should be denoted with \Drupal\Core\TypedData\DataDefinition::setRequired().

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An array of property definitions of contained properties, keyed by property name.

Overrides FieldItemInterface::propertyDefinitions

See also

\Drupal\Core\Field\BaseFieldDefinition

File

modules/field/src/Plugin/Field/FieldType/StockLevel.php, line 61

Class

StockLevel
Plugin implementation of the 'commerce_stock_field' field type.

Namespace

Drupal\commerce_stock_field\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $properties['value'] = DataDefinition::create('float')
    ->setLabel(t('Available stock'));
  $properties['available_stock'] = DataDefinition::create('float')
    ->setLabel(t('Available stock'))
    ->setComputed(TRUE)
    ->setInternal(FALSE)
    ->setReadOnly(TRUE)
    ->setClass('Drupal\\commerce_stock_field\\StockLevelProcessor')
    ->setSetting('stock level', 'summary');
  return $properties;
}