You are here

public static function ComputedFieldItem::propertyDefinitions in Computed Field 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

src/Plugin/Field/FieldType/ComputedFieldItem.php, line 54

Class

ComputedFieldItem
Plugin implementation of the 'computed' field type.

Namespace

Drupal\computed_field\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $type = $field_definition
    ->getSetting('data_type');
  if ($type == 'varchar' || $type == 'text') {
    $properties['value'] = DataDefinition::create('string')
      ->setLabel(t('Text value'))
      ->setSetting('case_sensitive', $field_definition
      ->getSetting('case_sensitive'))
      ->setRequired(TRUE);
  }
  if ($type == 'int') {
    $properties['value'] = DataDefinition::create('integer')
      ->setLabel(t('Integer value'))
      ->setRequired(TRUE);
  }
  if ($type == 'float') {
    $properties['value'] = DataDefinition::create('float')
      ->setLabel(t('Float'))
      ->setRequired(TRUE);
  }
  if ($type == 'decimal') {
    $properties['value'] = DataDefinition::create('string')
      ->setLabel(t('Decimal value'))
      ->setRequired(TRUE);
  }
  return $properties;
}