class ListIntegerItem
Same name and namespace in other branches
- 11.x core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php \Drupal\options\Plugin\Field\FieldType\ListIntegerItem
- 10 core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php \Drupal\options\Plugin\Field\FieldType\ListIntegerItem
- 8.9.x core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php \Drupal\options\Plugin\Field\FieldType\ListIntegerItem
- main core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php \Drupal\options\Plugin\Field\FieldType\ListIntegerItem
Plugin implementation of the 'list_integer' field type.
Plugin annotation
@FieldType(
id = "list_integer",
label = @Translation("List (integer)"),
description = @Translation("This field stores integer values from a list of allowed 'value => label' pairs, i.e. 'Lifetime in days': 1 => 1 day, 7 => 1 week, 31 => 1 month."),
category = @Translation("Number"),
default_widget = "options_select",
default_formatter = "list_default",
)
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\options\Plugin\Field\FieldType\ListItemBase implements \Drupal\Core\TypedData\OptionsProviderInterface extends \Drupal\Core\Field\FieldItemBase
- class \Drupal\options\Plugin\Field\FieldType\ListIntegerItem extends \Drupal\options\Plugin\Field\FieldType\ListItemBase
- class \Drupal\options\Plugin\Field\FieldType\ListItemBase implements \Drupal\Core\TypedData\OptionsProviderInterface 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 ListIntegerItem
1 file declares its use of ListIntegerItem
- XmlEntityNormalizationQuirksTrait.php in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ XmlEntityNormalizationQuirksTrait.php
File
-
core/
modules/ options/ src/ Plugin/ Field/ FieldType/ ListIntegerItem.php, line 22
Namespace
Drupal\options\Plugin\Field\FieldTypeView source
class ListIntegerItem extends ListItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('integer')->setLabel(new TranslatableMarkup('Integer value'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'int',
],
],
'indexes' => [
'value' => [
'value',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function allowedValuesDescription() {
$description = '<p>' . $this->t('The possible values this field can contain. Enter one value per line, in the format key|label.');
$description .= '<br/>' . $this->t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.');
$description .= '<br/>' . $this->t('The label is optional: if a line contains a single number, it will be used as key and label.');
$description .= '<br/>' . $this->t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');
$description .= '</p>';
$description .= '<p>' . $this->t('Allowed HTML tags in labels: @tags', [
'@tags' => FieldFilteredMarkup::displayAllowedTags(),
]) . '</p>';
return $description;
}
/**
* {@inheritdoc}
*/
protected static function validateAllowedValue($option) {
if (!preg_match('/^-?\\d+$/', $option)) {
return new TranslatableMarkup('Allowed values list: keys must be integers.');
}
}
/**
* {@inheritdoc}
*/
protected static function castAllowedValue($value) {
return (int) $value;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.