Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Field / Plugin / Field / FieldType / StringItemBase.php
diff --git a/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php b/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php
new file mode 100644 (file)
index 0000000..f59c10c
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\Core\Field\Plugin\Field\FieldType;
+
+use Drupal\Core\Field\FieldItemBase;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\Core\TypedData\DataDefinition;
+
+/**
+ * Base class for string field types.
+ */
+abstract class StringItemBase extends FieldItemBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function defaultStorageSettings() {
+    return [
+      'case_sensitive' => FALSE,
+    ] + parent::defaultStorageSettings();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
+    // This is called very early by the user entity roles field. Prevent
+    // early t() calls by using the TranslatableMarkup.
+    $properties['value'] = DataDefinition::create('string')
+      ->setLabel(new TranslatableMarkup('Text value'))
+      ->setSetting('case_sensitive', $field_definition->getSetting('case_sensitive'))
+      ->setRequired(TRUE);
+
+    return $properties;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isEmpty() {
+    $value = $this->get('value')->getValue();
+    return $value === NULL || $value === '';
+  }
+
+}