diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 1ac0682..62dce88 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -256,7 +256,17 @@ public function getCreatedTime() { * {@inheritdoc} */ public function getLastAccessedTime() { - return $this->get('access')->value; + // Optimize for the case where the field object has not been initialized + // yet, directly access the value. + // @todo Use getFieldValue(), see https://www.drupal.org/node/2580551. + if (!isset($this->fields['access'])) { + if (isset($this->values['access'][LanguageInterface::LANGCODE_DEFAULT][0]['value'])) { + return $this->values['access'][LanguageInterface::LANGCODE_DEFAULT][0]['value']; + } + } + else { + return $this->get('access')->value; + } } /** @@ -316,7 +326,17 @@ public function block() { * {@inheritdoc} */ public function getTimeZone() { - return $this->get('timezone')->value; + // Optimize for the case where the field object has not been initialized + // yet, directly access the value. + // @todo Use getFieldValue(), see https://www.drupal.org/node/2580551. + if (!isset($this->fields['timezone'])) { + if (isset($this->values['timezone'][LanguageInterface::LANGCODE_DEFAULT][0]['value'])) { + return $this->values['timezone'][LanguageInterface::LANGCODE_DEFAULT][0]['value']; + } + } + else { + return $this->get('timezone')->value; + } } /** @@ -378,7 +398,18 @@ public function getUsername() { * {@inheritdoc} */ public function getAccountName() { - return $this->get('name')->value ?: ''; + // Optimize for the case where the field object has not been initialized + // yet, directly access the value. + // @todo Use getFieldValue(), see https://www.drupal.org/node/2580551. + if (!isset($this->fields['name'])) { + if (isset($this->values['name'][LanguageInterface::LANGCODE_DEFAULT][0]['value'])) { + return $this->values['name'][LanguageInterface::LANGCODE_DEFAULT][0]['value']; + } + } + else { + return $this->get('name')->value; + } + return ''; } /**