Skip to content

Commit 9f92965

Browse files
authored
Add stubs for text field types (#783)
1 parent fc95fad commit 9f92965

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
namespace Drupal\Component\Render;
4+
5+
interface MarkupInterface extends \JsonSerializable, \Stringable {
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
namespace Drupal\text\Plugin\Field\FieldType;
4+
5+
class TextItem extends TextItemBase {
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Drupal\text\Plugin\Field\FieldType;
4+
5+
use Drupal\Core\Field\FieldItemBase;
6+
7+
/**
8+
* @property ?string $value
9+
* @property ?string $format
10+
* @property-read \Drupal\Component\Render\MarkupInterface $processed
11+
*/
12+
abstract class TextItemBase extends FieldItemBase {
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
namespace Drupal\text\Plugin\Field\FieldType;
4+
5+
class TextLongItem extends TextItemBase {
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Drupal\text\Plugin\Field\FieldType;
4+
5+
/**
6+
* @property ?string $summary
7+
* @property-read \Drupal\Component\Render\MarkupInterface $summary_processed
8+
*/
9+
class TextWithSummaryItem extends TextItemBase {
10+
}

tests/src/Type/data/field-types.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
use Drupal\file\Plugin\Field\FieldType\FileUriItem;
2323
use Drupal\link\Plugin\Field\FieldType\LinkItem;
2424
use Drupal\node\Entity\Node;
25+
use Drupal\text\Plugin\Field\FieldType\TextItem;
26+
use Drupal\text\Plugin\Field\FieldType\TextLongItem;
27+
use Drupal\text\Plugin\Field\FieldType\TextWithSummaryItem;
2528
use function PHPStan\Testing\assertType;
2629

2730
$node = Node::create(['type' => 'page']);
@@ -146,3 +149,28 @@
146149
assert($file_uri_field instanceof FileUriItem);
147150
assertType(FileUriItem::class, $file_uri_field);
148151
assertType('string', $file_uri_field->url);
152+
153+
// TextITem.
154+
$text_field = $node->get('field_text')->first();
155+
assert($text_field instanceof TextItem);
156+
assertType(TextItem::class, $text_field);
157+
assertType('string|null', $text_field->value);
158+
assertType('string|null', $text_field->format);
159+
assertType('Drupal\Component\Render\MarkupInterface', $text_field->processed);
160+
161+
// TextLongITem.
162+
$text_long_field = $node->get('field_text_long')->first();
163+
assert($text_long_field instanceof TextLongItem);
164+
assertType(TextLongItem::class, $text_long_field);
165+
assertType('string|null', $text_long_field->value);
166+
assertType('string|null', $text_long_field->format);
167+
assertType('Drupal\Component\Render\MarkupInterface', $text_long_field->processed);
168+
169+
// TextWithSummaryITem.
170+
$text_with_summary_field = $node->get('field_text_with_summary')->first();
171+
assert($text_with_summary_field instanceof TextWithSummaryItem);
172+
assertType(TextWithSummaryItem::class, $text_with_summary_field);
173+
assertType('string|null', $text_with_summary_field->value);
174+
assertType('string|null', $text_with_summary_field->format);
175+
assertType('string|null', $text_with_summary_field->summary);
176+
assertType('Drupal\Component\Render\MarkupInterface', $text_with_summary_field->summary_processed);

0 commit comments

Comments
 (0)