annotate core/modules/user/src/UserNameItem.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\user;
Chris@0 4
Chris@0 5 use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Defines a custom field item class for the 'name' user entity field.
Chris@0 9 */
Chris@0 10 class UserNameItem extends StringItem {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * {@inheritdoc}
Chris@0 14 */
Chris@0 15 public function isEmpty() {
Chris@0 16 $value = $this->get('value')->getValue();
Chris@0 17
Chris@0 18 // Take into account that the name of the anonymous user is an empty string.
Chris@0 19 if ($this->getEntity()->isAnonymous()) {
Chris@0 20 return $value === NULL;
Chris@0 21 }
Chris@0 22
Chris@0 23 return $value === NULL || $value === '';
Chris@0 24 }
Chris@0 25
Chris@0 26 }