Mercurial > hg > isophonics-drupal-site
annotate core/modules/user/src/UserNameItem.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 1fec387a4317 |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\user; |
Chris@0 | 4 |
Chris@14 | 5 use Drupal\Core\Field\FieldDefinitionInterface; |
Chris@0 | 6 use Drupal\Core\Field\Plugin\Field\FieldType\StringItem; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Defines a custom field item class for the 'name' user entity field. |
Chris@0 | 10 */ |
Chris@0 | 11 class UserNameItem extends StringItem { |
Chris@0 | 12 |
Chris@0 | 13 /** |
Chris@0 | 14 * {@inheritdoc} |
Chris@0 | 15 */ |
Chris@0 | 16 public function isEmpty() { |
Chris@0 | 17 $value = $this->get('value')->getValue(); |
Chris@0 | 18 |
Chris@0 | 19 // Take into account that the name of the anonymous user is an empty string. |
Chris@0 | 20 if ($this->getEntity()->isAnonymous()) { |
Chris@0 | 21 return $value === NULL; |
Chris@0 | 22 } |
Chris@0 | 23 |
Chris@0 | 24 return $value === NULL || $value === ''; |
Chris@0 | 25 } |
Chris@0 | 26 |
Chris@14 | 27 /** |
Chris@14 | 28 * {@inheritdoc} |
Chris@14 | 29 */ |
Chris@14 | 30 public static function generateSampleValue(FieldDefinitionInterface $field_definition) { |
Chris@14 | 31 $values = parent::generateSampleValue($field_definition); |
Chris@14 | 32 // User names larger than 60 characters won't pass validation. |
Chris@14 | 33 $values['value'] = substr($values['value'], 0, UserInterface::USERNAME_MAX_LENGTH); |
Chris@14 | 34 return $values; |
Chris@14 | 35 } |
Chris@14 | 36 |
Chris@0 | 37 } |