3 namespace Drupal\text\Plugin\Field\FieldType;
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\Core\Form\FormStateInterface;
9 * Plugin implementation of the 'text' field type.
13 * label = @Translation("Text (formatted)"),
14 * description = @Translation("This field stores a text with a text format."),
15 * category = @Translation("Text"),
16 * default_widget = "text_textfield",
17 * default_formatter = "text_default"
20 class TextItem extends TextItemBase {
25 public static function defaultStorageSettings() {
28 ] + parent::defaultStorageSettings();
34 public static function schema(FieldStorageDefinitionInterface $field_definition) {
39 'length' => $field_definition->getSetting('max_length'),
47 'format' => ['format'],
55 public function getConstraints() {
56 $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
57 $constraints = parent::getConstraints();
59 if ($max_length = $this->getSetting('max_length')) {
60 $constraints[] = $constraint_manager->create('ComplexData', [
64 'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]),
76 public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
79 $element['max_length'] = [
81 '#title' => t('Maximum length'),
82 '#default_value' => $this->getSetting('max_length'),
84 '#description' => t('The maximum length of the field in characters.'),
86 '#disabled' => $has_data,
88 $element += parent::storageSettingsForm($form, $form_state, $has_data);