You are here

public static function UserNameItem::generateSampleValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/UserNameItem.php \Drupal\user\UserNameItem::generateSampleValue()

Generates placeholder field values.

Useful when populating site with placeholder content during site building or profiling.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

Return value

array An associative array of values.

Overrides StringItem::generateSampleValue

File

core/modules/user/src/UserNameItem.php, line 30

Class

UserNameItem
Defines a custom field item class for the 'name' user entity field.

Namespace

Drupal\user

Code

public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
  $values = parent::generateSampleValue($field_definition);

  // User names larger than 60 characters won't pass validation.
  $values['value'] = substr($values['value'], 0, UserInterface::USERNAME_MAX_LENGTH);
  return $values;
}