UserNameItem.php in Drupal 9
File
core/modules/user/src/UserNameItem.php
View source
<?php
namespace Drupal\user;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
class UserNameItem extends StringItem {
public function isEmpty() {
$value = $this
->get('value')
->getValue();
if ($this
->getEntity()
->isAnonymous()) {
return $value === NULL;
}
return $value === NULL || $value === '';
}
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$values = parent::generateSampleValue($field_definition);
$values['value'] = substr($values['value'], 0, UserInterface::USERNAME_MAX_LENGTH);
return $values;
}
}
Classes
Name |
Description |
UserNameItem |
Defines a custom field item class for the 'name' user entity field. |