You are here

public static function DateRangeItem::propertyDefinitions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime_range/src/Plugin/Field/FieldType/DateRangeItem.php \Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem::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 DateTimeItem::propertyDefinitions

See also

\Drupal\Core\Field\BaseFieldDefinition

File

core/modules/datetime_range/src/Plugin/Field/FieldType/DateRangeItem.php, line 35

Class

DateRangeItem
Plugin implementation of the 'daterange' field type.

Namespace

Drupal\datetime_range\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $properties['value'] = DataDefinition::create('datetime_iso8601')
    ->setLabel(t('Start date value'))
    ->setRequired(TRUE);
  $properties['start_date'] = DataDefinition::create('any')
    ->setLabel(t('Computed start date'))
    ->setDescription(t('The computed start DateTime object.'))
    ->setComputed(TRUE)
    ->setClass(DateTimeComputed::class)
    ->setSetting('date source', 'value');
  $properties['end_value'] = DataDefinition::create('datetime_iso8601')
    ->setLabel(t('End date value'))
    ->setRequired(TRUE);
  $properties['end_date'] = DataDefinition::create('any')
    ->setLabel(t('Computed end date'))
    ->setDescription(t('The computed end DateTime object.'))
    ->setComputed(TRUE)
    ->setClass(DateTimeComputed::class)
    ->setSetting('date source', 'end_value');
  return $properties;
}