StringItem.php 1.37 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Entity\Plugin\Field\FieldType\StringItem.
6 7
 */

8
namespace Drupal\Core\Field\Plugin\Field\FieldType;
9

10
use Drupal\Core\Field\FieldDefinitionInterface;
11
use Drupal\Core\Field\FieldItemBase;
12
use Drupal\Core\TypedData\DataDefinition;
13 14

/**
15
 * Defines the 'string' entity field type.
16
 *
17 18 19
 * @FieldType(
 *   id = "string",
 *   label = @Translation("String"),
20
 *   description = @Translation("An entity field containing a string value."),
21 22 23
 *   settings = {
 *     "max_length" = "255"
 *   },
24
 *   configurable = FALSE
25
 * )
26 27 28 29
 */
class StringItem extends FieldItemBase {

  /**
30
   * Definitions of the contained properties.
31
   *
32
   * @see StringItem::getPropertyDefinitions()
33 34 35 36 37 38
   *
   * @var array
   */
  static $propertyDefinitions;

  /**
39
   * {@inheritdoc}
40 41 42
   */
  public function getPropertyDefinitions() {

43
    if (!isset(static::$propertyDefinitions)) {
44 45
      static::$propertyDefinitions['value'] = DataDefinition::create('string')
        ->setLabel(t('Text value'));
46
    }
47
    return static::$propertyDefinitions;
48
  }
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

  /**
   * {@inheritdoc}
   */
  public static function schema(FieldDefinitionInterface $field_definition) {
    return array(
      'columns' => array(
        'value' => array(
          'type' => 'varchar',
          'length' => $field_definition->getSetting('max_length'),
          'not null' => FALSE,
        ),
      ),
    );
  }

65
}