Skip to content

Commit

Permalink
Add stubs for datetime field type
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesgeene committed Jul 11, 2024
1 parent 9f92965 commit b2b0075
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions stubs/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Drupal\datetime\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemBase;

/**
* @property ?string $value
* @property-read ?\Drupal\Core\Datetime\DrupalDateTime $date
*/
class DateTimeItem extends FieldItemBase implements DateTimeItemInterface {

}
8 changes: 8 additions & 0 deletions tests/src/Type/data/field-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem;
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\file\Plugin\Field\FieldType\FileItem;
use Drupal\file\Plugin\Field\FieldType\FileUriItem;
use Drupal\link\Plugin\Field\FieldType\LinkItem;
Expand Down Expand Up @@ -137,6 +138,13 @@
assertType(UuidItem::class, $uuid_field);
assertType('string', $uuid_field->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);
Expand Down

0 comments on commit b2b0075

Please sign in to comment.