SerializedItem.php in Drupal 9
Same filename and directory in other branches
File
core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/SerializedItem.phpView source
<?php
namespace Drupal\entity_test\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\DataDefinition;
/**
* Defines the 'serialized_item' entity field type.
*
* @FieldType(
* id = "serialized_item_test",
* label = @Translation("Test serialized field item"),
* description = @Translation("A field containing a serialized string value."),
* category = @Translation("Field"),
* )
*/
class SerializedItem extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(new TranslatableMarkup('Test serialized value'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
],
],
];
}
}
Classes
Name | Description |
---|---|
SerializedItem | Defines the 'serialized_item' entity field type. |