You are here

public static function DateTimeDayItem::propertyDefinitions in Date time day 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 DateTimeItem::propertyDefinitions

See also

\Drupal\Core\Field\BaseFieldDefinition

File

src/Plugin/Field/FieldType/DateTimeDayItem.php, line 48

Class

DateTimeDayItem
Plugin implementation of the 'datetimeday' field type.

Namespace

Drupal\date_time_day\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $properties = parent::propertyDefinitions($field_definition);

  /** @var \Drupal\Core\TypedData\DataDefinition $date */
  $date = $properties['date'];
  $date
    ->setClass(DateDayComputed::class);
  $properties['start_time_value'] = DataDefinition::create('string')
    ->setLabel(t('Start time value'))
    ->setRequired(TRUE);
  $properties['start_time'] = DataDefinition::create('any')
    ->setLabel(t('Computed start time'))
    ->setDescription(t('The computed start DateTime object.'))
    ->setComputed(TRUE)
    ->setClass(DateTimeDayComputed::class)
    ->setSetting('date source', 'start_time_value');
  $properties['end_time_value'] = DataDefinition::create('string')
    ->setLabel(t('End time value'))
    ->setRequired(TRUE);
  $properties['end_time'] = DataDefinition::create('any')
    ->setLabel(t('Computed end time'))
    ->setDescription(t('The computed end DateTime object.'))
    ->setComputed(TRUE)
    ->setClass(DateTimeDayComputed::class)
    ->setSetting('date source', 'end_time_value');
  return $properties;
}