diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index 9b7020a..45ae1e6 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -275,6 +275,12 @@ public function save(EntityInterface $entity) { // Ensure we are dealing with the actual entity. $entity = $entity->getNGEntity(); + // There are some cases that pre-set ->original for performance. Make sure + // original is not a BC decorator. + if ($entity->original instanceof \Drupal\Core\Entity\EntityBCDecorator) { + $entity->original = $entity->original->getNGEntity(); + } + // Sync the changes made in the fields array to the internal values array. $entity->updateOriginalValues(); diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 37311dc..e1abc47 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -10,6 +10,7 @@ use Drupal\Component\Uuid\Uuid; use Drupal\Core\Language\Language; use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\user\UserInterface; use IteratorAggregate; /** @@ -257,7 +258,7 @@ public function getIterator() { /** * Implements \Drupal\Core\TypedData\AccessibleInterface::access(). */ - public function access($operation = 'view', \Drupal\user\UserInterface $account = NULL) { + public function access($operation = 'view', UserInterface $account = NULL) { return \Drupal::entityManager() ->getAccessController($this->entityType) ->access($this, $operation, LANGUAGE_DEFAULT, $account); diff --git a/core/lib/Drupal/Core/TypedData/AccessibleInterface.php b/core/lib/Drupal/Core/TypedData/AccessibleInterface.php index 40b4645..a268573 100644 --- a/core/lib/Drupal/Core/TypedData/AccessibleInterface.php +++ b/core/lib/Drupal/Core/TypedData/AccessibleInterface.php @@ -7,6 +7,8 @@ namespace Drupal\Core\TypedData; +use Drupal\user\UserInterface; + /** * Interface for checking access. */ @@ -32,6 +34,6 @@ * * @todo Don't depend on module level code. */ - public function access($operation = 'view', \Drupal\user\UserInterface $account = NULL); + public function access($operation = 'view', UserInterface $account = NULL); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php index 7b8aa9a..57869c4 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php @@ -74,7 +74,7 @@ public function setUp() { 'label' => 'User name', 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock', 'context' => array( - 'user' => array('class' => 'Drupal\user\Plugin\Core\Entity\User') + 'user' => array('class' => 'Drupal\user\\UserInterface') ), ), 'string_context' => array( @@ -88,7 +88,7 @@ public function setUp() { 'label' => 'Complex context', 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockComplexContextBlock', 'context' => array( - 'user' => array('class' => 'Drupal\user\Plugin\Core\Entity\User'), + 'user' => array('class' => 'Drupal\user\\UserInterface'), 'node' => array('class' => 'Drupal\Core\Entity\EntityBCDecorator'), ), ), diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index db12835..c820f67 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -225,7 +225,7 @@ public function form(array $form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::buildEntity(). + * {@inheritdoc} */ public function buildEntity(array $form, array &$form_state) { // Change the roles array to a list of enabled roles. diff --git a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php index b338eef..5a92181 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php @@ -193,12 +193,15 @@ class User extends EntityNG implements UserInterface { ); /** - * Implements Drupal\Core\Entity\EntityInterface::id(). + * {@inheritdoc} */ public function id() { return $this->get('uid')->value; } + /** + * {@inheritdoc} + */ protected function init() { parent::init(); unset($this->access); @@ -220,6 +223,9 @@ protected function init() { unset($this->uuid); } + /** + * {@inheritdoc} + */ public function getBCEntity() { if (!isset($this->bcEntity)) { // Initialize field definitions so that we can pass them by reference. @@ -229,5 +235,4 @@ public function getBCEntity() { return $this->bcEntity; } - } diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index 816511b..85acfa3 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -65,12 +65,6 @@ public function save(EntityInterface $entity) { $entity->uid->value = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); $entity->enforceIsNew(); } - - // There are some cases that pre-set ->original for performance. Make sure - // original is not a BC decorator. - if ($entity->original instanceof \Drupal\Core\Entity\EntityBCDecorator) { - $entity->original = $entity->original->getNGEntity(); - } parent::save($entity); } @@ -114,15 +108,12 @@ protected function postSave(EntityInterface $entity, $update) { // user and recreate the current one. if ($entity->pass->value != $entity->original->pass->value) { drupal_session_destroy_uid($entity->id()); - if ($entity->uid->value == $GLOBALS['user']->uid) { + if ($entity->id() == $GLOBALS['user']->uid) { drupal_session_regenerate(); } } - // Remove roles that are no longer enabled for the user. - //$entity->roles = array_filter($entity->roles); - - // Reload user roles if provided. + // Update user roles if changed. if ($entity->roles->getValue() != $entity->original->roles->getValue()) { db_delete('users_roles') ->condition('uid', $entity->id()) @@ -180,7 +171,7 @@ protected function postDelete($entities) { } /** - * Overrides \Drupal\Core\Entity\DataBaseStorageControllerNG::invokeHook(). + * {@inheritdoc} */ protected function invokeHook($hook, EntityInterface $entity) { $function = 'field_attach_' . $hook; @@ -194,13 +185,13 @@ protected function invokeHook($hook, EntityInterface $entity) { } // Invoke the hook. - module_invoke_all($this->entityType . '_' . $hook, $entity->getBCEntity()); + \Drupal::moduleHandler()->invokeAll($this->entityType . '_' . $hook, $entity->getBCEntity()); // Invoke the respective entity-level hook. - module_invoke_all('entity_' . $hook, $entity->getBCEntity(), $this->entityType); + \Drupal::moduleHandler()->invokeAll('entity_' . $hook, $entity->getBCEntity(), $this->entityType); } /** - * Overrides \Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions(). + * {@inheritdoc} */ public function baseFieldDefinitions() { $properties['uid'] = array(