From 11876ad4fedfacdde397b7ab362438a661ffb5b1 Mon Sep 17 00:00:00 2001 From: Cees Geene Date: Thu, 11 Jul 2024 21:59:17 +0200 Subject: [PATCH 1/4] Add stubs for datetime field type --- .../Plugin/Field/FieldType/DateTimeItem.stub | 13 +++++++++++++ .../Field/FieldType/DateTimeItemInterface.stub | 6 ++++++ tests/src/Type/data/field-types.php | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub create mode 100644 stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItemInterface.stub diff --git a/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub b/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub new file mode 100644 index 00000000..a775e4a5 --- /dev/null +++ b/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub @@ -0,0 +1,13 @@ +value); +// DateTimeItem. +$datetime_field = $node->get('field_datetime')->first(); +assert($datetime_field instanceof DateTimeItem); +assertType(DateTimeItem::class, $datetime_field); +assertType('string|null', $datetime_field->value); +assertType('Drupal\Core\Datetime\DrupalDateTime|null', $datetime_field->date); + // FileItem. $file_field = $node->get('field_file')->first(); assert($file_field instanceof FileItem); From 4ccdf104b997d944a0bfcfb644a61197ed750351 Mon Sep 17 00:00:00 2001 From: Cees Geene Date: Sat, 20 Jul 2024 16:40:09 +0200 Subject: [PATCH 2/4] Set date property of DateTimeItem to be writable --- stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub b/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub index a775e4a5..a05315e3 100644 --- a/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub +++ b/stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub @@ -6,7 +6,7 @@ use Drupal\Core\Field\FieldItemBase; /** * @property ?string $value - * @property-read ?\Drupal\Core\Datetime\DrupalDateTime $date + * @property ?\Drupal\Core\Datetime\DrupalDateTime $date */ class DateTimeItem extends FieldItemBase implements DateTimeItemInterface { From 06c3e22a285bff4964d226880ef6a40497f2808a Mon Sep 17 00:00:00 2001 From: Cees Geene Date: Thu, 11 Jul 2024 22:04:11 +0200 Subject: [PATCH 3/4] Add stubs for daterange field type --- .../Plugin/Field/FieldType/DateRangeItem.stub | 17 +++++++++++++++++ tests/src/Type/data/field-types.php | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub diff --git a/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub b/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub new file mode 100644 index 00000000..a081a3c0 --- /dev/null +++ b/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub @@ -0,0 +1,17 @@ +value); assertType('Drupal\Core\Datetime\DrupalDateTime|null', $datetime_field->date); +// DateRangeItem. +$daterange_field = $node->get('field_daterange')->first(); +assert($daterange_field instanceof DateRangeItem); +assertType(DateRangeItem::class, $daterange_field); +assertType('string|null', $daterange_field->value); +assertType('Drupal\Core\Datetime\DrupalDateTime|null', $daterange_field->start_date); +assertType('string|null', $daterange_field->end_value); +assertType('Drupal\Core\Datetime\DrupalDateTime|null', $daterange_field->end_date); + // FileItem. $file_field = $node->get('field_file')->first(); assert($file_field instanceof FileItem); From 9b4a099d4767ef2545620269f202f6d64fb41572 Mon Sep 17 00:00:00 2001 From: Cees Geene Date: Sat, 20 Jul 2024 16:41:22 +0200 Subject: [PATCH 4/4] Use property instead of property-read --- .../Plugin/Field/FieldType/DateRangeItem.stub | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub b/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub index a081a3c0..e1b81068 100644 --- a/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub +++ b/stubs/Drupal/datetime_range/Plugin/Field/FieldType/DateRangeItem.stub @@ -5,12 +5,12 @@ namespace Drupal\datetime_range\Plugin\Field\FieldType; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; /** - * @property-read null $date + * @property null $date * Even though this extends DateTimeItem, the date property does not actually * exist. It is not possible to undo a property definition. - * @property-read ?\Drupal\Core\Datetime\DrupalDateTime $start_date + * @property ?\Drupal\Core\Datetime\DrupalDateTime $start_date * @property ?string $end_value - * @property-read ?\Drupal\Core\Datetime\DrupalDateTime $end_date + * @property ?\Drupal\Core\Datetime\DrupalDateTime $end_date */ class DateRangeItem extends DateTimeItem {