Skip to content

Commit

Permalink
Add stubs for daterange field type
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesgeene committed Jul 12, 2024
1 parent 8893a5b commit 8de9dcb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Drupal\datetime_range\Plugin\Field\FieldType;

use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;

/**
* @property-read 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 ?string $end_value
* @property-read ?\Drupal\Core\Datetime\DrupalDateTime $end_date
*/
class DateRangeItem extends DateTimeItem {

}
10 changes: 10 additions & 0 deletions tests/src/Type/data/field-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Drupal\Core\Field\Plugin\Field\FieldType\UriItem;
use Drupal\Core\Field\Plugin\Field\FieldType\UuidItem;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
use Drupal\file\Plugin\Field\FieldType\FileItem;
use Drupal\file\Plugin\Field\FieldType\FileUriItem;
use Drupal\link\Plugin\Field\FieldType\LinkItem;
Expand Down Expand Up @@ -145,6 +146,15 @@
assertType('string|null', $datetime_field->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);
Expand Down

0 comments on commit 8de9dcb

Please sign in to comment.