function UserNameItem::generateSampleValue

Same name in other branches
  1. 9 core/modules/user/src/UserNameItem.php \Drupal\user\UserNameItem::generateSampleValue()
  2. 10 core/modules/user/src/UserNameItem.php \Drupal\user\UserNameItem::generateSampleValue()
  3. 11.x core/modules/user/src/UserNameItem.php \Drupal\user\UserNameItem::generateSampleValue()

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.