You are here

public static function DoubleField::propertyDefinitions 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::propertyDefinitions()

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/DoubleField.php, line 424

Class

DoubleField
Plugin implementation of the 'double_field' field type.

Namespace

Drupal\double_field\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $subfield_types = static::subfieldTypes();
  $settings = $field_definition
    ->getSettings();
  $properties = [];
  foreach ([
    'first',
    'second',
  ] as $subfield) {
    $subfield_type = $settings['storage'][$subfield]['type'];

    // Typed data are slightly different from schema the definition.
    if ($subfield_type == 'text' || $subfield_type == 'telephone') {
      $subfield_type = 'string';
    }
    elseif ($subfield_type == 'numeric') {
      $subfield_type = 'float';
    }
    $properties[$subfield] = DataDefinition::create($subfield_type)
      ->setLabel($subfield_types[$subfield_type]);
  }
  return $properties;
}