class TextItem
Plugin implementation of the 'text' field type.
Attributes
#[FieldType(id: "text", label: new TranslatableMarkup("Text (formatted)"), description: [
new TranslatableMarkup("Ideal for titles and names that need to support markup such as bold, italics or links"),
new TranslatableMarkup("Efficient storage for short text"),
new TranslatableMarkup("Requires specifying a maximum length"),
new TranslatableMarkup("Good for fields with known or predictable lengths"),
], category: "formatted_text", default_widget: "text_textfield", default_formatter: "text_default", list_class: TextFieldItemList::class)]
Hierarchy
- class \Drupal\Core\TypedData\TypedData implements \Drupal\Core\TypedData\TypedDataInterface, \Drupal\Component\Plugin\PluginInspectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\TypedData\TypedDataTrait
- class \Drupal\Core\TypedData\Plugin\DataType\Map implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ComplexDataInterface extends \Drupal\Core\TypedData\TypedData
- class \Drupal\Core\Field\FieldItemBase implements \Drupal\Core\Field\FieldItemInterface extends \Drupal\Core\TypedData\Plugin\DataType\Map
- class \Drupal\text\Plugin\Field\FieldType\TextItemBase extends \Drupal\Core\Field\FieldItemBase
- class \Drupal\text\Plugin\Field\FieldType\TextItem extends \Drupal\text\Plugin\Field\FieldType\TextItemBase
- class \Drupal\text\Plugin\Field\FieldType\TextItemBase extends \Drupal\Core\Field\FieldItemBase
- class \Drupal\Core\Field\FieldItemBase implements \Drupal\Core\Field\FieldItemInterface extends \Drupal\Core\TypedData\Plugin\DataType\Map
- class \Drupal\Core\TypedData\Plugin\DataType\Map implements \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ComplexDataInterface extends \Drupal\Core\TypedData\TypedData
Expanded class hierarchy of TextItem
File
-
core/
modules/ text/ src/ Plugin/ Field/ FieldType/ TextItem.php, line 13
Namespace
Drupal\text\Plugin\Field\FieldTypeView source
class TextItem extends TextItemBase {
/**
* {@inheritdoc}
*/
public static function defaultStorageSettings() {
return [
'max_length' => 255,
] + parent::defaultStorageSettings();
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => $field_definition->getSetting('max_length'),
],
'format' => [
'type' => 'varchar',
'length' => 255,
],
],
'indexes' => [
'format' => [
'format',
],
],
];
}
/**
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
if ($max_length = $this->getSetting('max_length')) {
$constraints[] = $constraint_manager->create('ComplexData', [
'value' => [
'Length' => [
'max' => $max_length,
'maxMessage' => $this->t('%name: the text may not be longer than @max characters.', [
'%name' => $this->getFieldDefinition()
->getLabel(),
'@max' => $max_length,
]),
],
],
]);
}
return $constraints;
}
/**
* {@inheritdoc}
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = [];
$element['max_length'] = [
'#type' => 'number',
'#title' => $this->t('Maximum length'),
'#default_value' => $this->getSetting('max_length'),
'#required' => TRUE,
'#description' => $this->t('The maximum length of the field in characters.'),
'#min' => 1,
'#disabled' => $has_data,
];
$element += parent::storageSettingsForm($form, $form_state, $has_data);
return $element;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.