StringItemBase.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php
  3. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php

Namespace

Drupal\Core\Field\Plugin\Field\FieldType

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php

View source
<?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 === '';
    }

}

Classes

Title Deprecated Summary
StringItemBase Base class for string field types.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.