Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Field / Plugin / Field / FieldType / StringItemBase.php
1 <?php
2
3 namespace Drupal\Core\Field\Plugin\Field\FieldType;
4
5 use Drupal\Core\Field\FieldItemBase;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
7 use Drupal\Core\StringTranslation\TranslatableMarkup;
8 use Drupal\Core\TypedData\DataDefinition;
9
10 /**
11  * Base class for string field types.
12  */
13 abstract class StringItemBase extends FieldItemBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static function defaultStorageSettings() {
19     return [
20       'case_sensitive' => FALSE,
21     ] + parent::defaultStorageSettings();
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
28     // This is called very early by the user entity roles field. Prevent
29     // early t() calls by using the TranslatableMarkup.
30     $properties['value'] = DataDefinition::create('string')
31       ->setLabel(new TranslatableMarkup('Text value'))
32       ->setSetting('case_sensitive', $field_definition->getSetting('case_sensitive'))
33       ->setRequired(TRUE);
34
35     return $properties;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function isEmpty() {
42     $value = $this->get('value')->getValue();
43     return $value === NULL || $value === '';
44   }
45
46 }