class TelephoneItem
Same name and namespace in other branches
- 9 core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem
- 8.9.x core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem
- 10 core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem
Plugin implementation of the 'telephone' field type.
Attributes
#[FieldType(id: "telephone", label: new TranslatableMarkup("Telephone number"), description: new TranslatableMarkup("This field stores a telephone number."), default_widget: "telephone_default", default_formatter: "basic_string")]
Hierarchy
- class \Drupal\Core\TypedData\TypedData extends \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 extends \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ComplexDataInterface implements \Drupal\Core\TypedData\TypedData
- class \Drupal\Core\Field\FieldItemBase extends \Drupal\Core\Field\FieldItemInterface implements \Drupal\Core\TypedData\Plugin\DataType\Map
- class \Drupal\telephone\Plugin\Field\FieldType\TelephoneItem implements \Drupal\Core\Field\FieldItemBase
- class \Drupal\Core\Field\FieldItemBase extends \Drupal\Core\Field\FieldItemInterface implements \Drupal\Core\TypedData\Plugin\DataType\Map
- class \Drupal\Core\TypedData\Plugin\DataType\Map extends \Drupal\Core\TypedData\Plugin\DataType\IteratorAggregate, \Drupal\Core\TypedData\ComplexDataInterface implements \Drupal\Core\TypedData\TypedData
Expanded class hierarchy of TelephoneItem
2 files declare their use of TelephoneItem
- TelephoneDefaultWidget.php in core/
modules/ telephone/ src/ Plugin/ Field/ FieldWidget/ TelephoneDefaultWidget.php - TelephoneFieldTest.php in core/
modules/ telephone/ tests/ src/ Functional/ TelephoneFieldTest.php
File
-
core/
modules/ telephone/ src/ Plugin/ Field/ FieldType/ TelephoneItem.php, line 15
Namespace
Drupal\telephone\Plugin\Field\FieldTypeView source
class TelephoneItem extends FieldItemBase {
/**
* The maximum length for a telephone value.
*/
const MAX_LENGTH = 256;
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => self::MAX_LENGTH,
],
],
];
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('Telephone number'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')
->getValue();
return $value === NULL || $value === '';
}
/**
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', [
'value' => [
'Length' => [
'max' => self::MAX_LENGTH,
'maxMessage' => $this->t('%name: the telephone number may not be longer than @max characters.', [
'%name' => $this->getFieldDefinition()
->getLabel(),
'@max' => self::MAX_LENGTH,
]),
],
],
]);
return $constraints;
}
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$values['value'] = rand(pow(10, 8), pow(10, 9) - 1);
return $values;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.