[ 'value' => [ 'type' => 'varchar', 'length' => 256, ], ], ]; } /** * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') ->setLabel(t('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(); $max_length = 256; $constraints[] = $constraint_manager->create('ComplexData', [ 'value' => [ 'Length' => [ 'max' => $max_length, 'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), ], ], ]); return $constraints; } /** * {@inheritdoc} */ public static function generateSampleValue(FieldDefinitionInterface $field_definition) { $values['value'] = rand(pow(10, 8), pow(10, 9) - 1); return $values; } }