You are here

public static function DateRecurItem::propertyDefinitions in Recurring Dates Field 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldType/DateRecurItem.php \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem::propertyDefinitions()
  2. 8 src/Plugin/Field/FieldType/DateRecurItem.php \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem::propertyDefinitions()
  3. 3.x src/Plugin/Field/FieldType/DateRecurItem.php \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem::propertyDefinitions()
  4. 3.1.x src/Plugin/Field/FieldType/DateRecurItem.php \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem::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 DateRangeItem::propertyDefinitions

See also

\Drupal\Core\Field\BaseFieldDefinition

1 call to DateRecurItem::propertyDefinitions()
DateRecurSubItem::propertyDefinitions in tests/modules/date_recur_subfield/src/Plugin/Field/FieldType/DateRecurSubItem.php
Defines field item properties.
1 method overrides DateRecurItem::propertyDefinitions()
DateRecurSubItem::propertyDefinitions in tests/modules/date_recur_subfield/src/Plugin/Field/FieldType/DateRecurSubItem.php
Defines field item properties.

File

src/Plugin/Field/FieldType/DateRecurItem.php, line 83

Class

DateRecurItem
Plugin implementation of the 'date_recur' field type.

Namespace

Drupal\date_recur\Plugin\Field\FieldType

Code

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

  /** @var \Drupal\Core\TypedData\DataDefinition $startDateProperty */
  $startDateProperty = $properties['start_date'];
  $startDateProperty
    ->setClass(DateRecurDateTimeComputed::class);

  /** @var \Drupal\Core\TypedData\DataDefinition $endDateProperty */
  $endDateProperty = $properties['end_date'];
  $endDateProperty
    ->setClass(DateRecurDateTimeComputed::class);
  $properties['rrule'] = DataDefinition::create('string')
    ->setLabel((string) new TranslatableMarkup('RRule'))
    ->setRequired(FALSE);
  $rruleMaxLength = $field_definition
    ->getSetting('rrule_max_length');
  assert(empty($rruleMaxLength) || is_numeric($rruleMaxLength) && $rruleMaxLength > 0);
  if (!empty($rruleMaxLength)) {
    $properties['rrule']
      ->addConstraint('Length', [
      'max' => $rruleMaxLength,
    ]);
  }
  $properties['timezone'] = DataDefinition::create('string')
    ->setLabel((string) new TranslatableMarkup('Timezone'))
    ->setRequired(TRUE)
    ->addConstraint('DateRecurTimeZone');
  $properties['infinite'] = DataDefinition::create('boolean')
    ->setLabel((string) new TranslatableMarkup('Whether the RRule is an infinite rule. Derived value from RRULE.'))
    ->setRequired(FALSE);
  $properties['occurrences'] = ListDataDefinition::create('any')
    ->setLabel((string) new TranslatableMarkup('Occurrences'))
    ->setComputed(TRUE)
    ->setClass(DateRecurOccurrencesComputed::class);
  return $properties;
}