improvements-2.x-dev/modules/improvements_views/src/Plugin/Field/FieldType/ViewsItem.php
modules/improvements_views/src/Plugin/Field/FieldType/ViewsItem.php
<?php namespace Drupal\improvements_views\Plugin\Field\FieldType; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; /** * @FieldType( * id = "views", * label = @Translation("Views"), * description = @Translation("Field for storing data about Views (View id and display name)."), * default_widget = "views_widget", * default_formatter = "views_formatter", * ) */ class ViewsItem extends FieldItemBase { /** * {@inheritDoc} */ public static function schema(FieldStorageDefinitionInterface $field_definition): array { return [ 'columns' => [ 'value' => [ 'type' => 'varchar', 'length' => 255, 'description' => 'View id and display name', ], ], ]; } /** * {@inheritDoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition): array { $properties['value'] = DataDefinition::create('string') ->setLabel(new TranslatableMarkup('View id and display name')) ->setRequired(TRUE); return $properties; } }