diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 25e9b9a..5f2998c 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -18,7 +18,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Lock\DatabaseLockBackend; use Drupal\Core\Lock\LockBackendInterface; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\UserSession; /** * @file @@ -1903,8 +1903,8 @@ function drupal_set_title($title = NULL, $output = CHECK_PLAIN) { /** * Generates a default anonymous $user object. * - * @return Drupal\user\Plugin\Core\Entity\User - * The user object. + * @return \Drupal\Core\Session\AccountInterface + * The user session object. */ function drupal_anonymous_user() { $values = array( @@ -1914,7 +1914,7 @@ function drupal_anonymous_user() { DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, ), ); - return new User($values, 'user'); + return new UserSession($values); } /** diff --git a/core/includes/session.inc b/core/includes/session.inc index b96b3d3..4420f1f 100644 --- a/core/includes/session.inc +++ b/core/includes/session.inc @@ -18,6 +18,8 @@ use Drupal\Component\Utility\Crypt; +use Drupal\Core\Session\UserSession; + /** * Session handler assigned by session_set_save_handler(). * @@ -91,22 +93,26 @@ function _drupal_session_read($sid) { // a HTTPS session or we are about to log in so we check the sessions table // for an anonymous session with the non-HTTPS-only cookie. if (Drupal::request()->isSecure()) { - $user = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.ssid = :ssid", array(':ssid' => $sid))->fetchObject(); - if (!$user) { + $values = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.ssid = :ssid", array(':ssid' => $sid))->fetchObject(); + if (!$values) { if (isset($_COOKIE[$insecure_session_name])) { - $user = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid AND s.uid = 0", array( + $values = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid AND s.uid = 0", array( ':sid' => $_COOKIE[$insecure_session_name])) - ->fetchObject(); + ->fetchAssoc(); } } } else { - $user = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(':sid' => $sid))->fetchObject(); + $values = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = :sid", array(':sid' => $sid))->fetchObject(); + } + + if ($values) { + $user = new UserSession($values); } // We found the client's session record and they are an authenticated, // active user. - if ($user && $user->uid > 0 && $user->status == 1) { + if ($user && $user->id() > 0 && $user->status() == 1) { // Add roles element to $user. $user->roles = array(); $user->roles[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID; diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index d48d0b7..48f2214 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -11,6 +11,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\TypedData\TypedDataInterface; use IteratorAggregate; +use Drupal\Core\Session\AccountInterface; /** * Defines a base entity class. @@ -257,7 +258,7 @@ public function getIterator() { /** * Implements \Drupal\Core\TypedData\AccessibleInterface::access(). */ - public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $account = NULL) { + public function access($operation = 'view', AccountInterface $account = NULL) { return \Drupal::entityManager() ->getAccessController($this->entityType) ->access($this, $operation, LANGUAGE_DEFAULT, $account); diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index 9b75d53..c71d87d 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Entity; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines a default implementation for entity access controllers. @@ -24,7 +24,7 @@ class EntityAccessController implements EntityAccessControllerInterface { /** * {@inheritdoc} */ - public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, AccountInterface $account = NULL) { // @todo Remove this once we can rely on $account. if (!$account) { @@ -79,7 +79,7 @@ public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE * TRUE if access was granted, FALSE if access was denied and NULL if access * could not be determined. */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { return NULL; } @@ -101,7 +101,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, U * is no record for the given user, operation, langcode and entity in the * cache. */ - protected function getCache(EntityInterface $entity, $operation, $langcode, User $account) { + protected function getCache(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { $uid = $account ? $account->id() : 0; $uuid = $entity->uuid(); @@ -127,7 +127,7 @@ protected function getCache(EntityInterface $entity, $operation, $langcode, User * @return bool * TRUE if access was granted, FALSE otherwise. */ - protected function setCache($access, EntityInterface $entity, $operation, $langcode, User $account) { + protected function setCache($access, EntityInterface $entity, $operation, $langcode, AccountInterface $account) { $uid = $account ? $account->id() : 0; $uuid = $entity->uuid(); diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php index ddf3dfd..5ad5767 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php @@ -7,8 +7,7 @@ namespace Drupal\Core\Entity; -// @todo Don't depend on module level code. -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines a common interface for entity access controller classes. @@ -26,14 +25,14 @@ * @param string $langcode * (optional) The language code for which to check access. Defaults to * LANGUAGE_DEFAULT. - * @param \Drupal\user\Plugin\Core\Entity\User $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. + * @param \Drupal\Core\Session\AccountInterface $account + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. * * @return bool * TRUE if access was granted, FALSE otherwise. */ - public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL); + public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, AccountInterface $account = NULL); /** * Clears all cached access checks. diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index 9697648..62fc8fe 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -10,6 +10,7 @@ use IteratorAggregate; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\Core\Session\AccountInterface; /** * Provides backwards compatible (BC) access to entity fields. @@ -211,7 +212,7 @@ function __clone() { /** * Forwards the call to the decorated entity. */ - public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $account = NULL) { + public function access($operation = 'view', AccountInterface $account = NULL) { return $this->decorated->access($operation, $account); } diff --git a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php b/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php index 4dc7657..859fa9a 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/EntityTranslation.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity\Field\Type; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AccessibleInterface; use Drupal\Core\TypedData\ComplexDataInterface; use Drupal\Core\TypedData\TypedData; @@ -210,7 +211,7 @@ public function onChange($property_name) { /** * Implements \Drupal\Core\TypedData\AccessibleInterface::access(). */ - public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $account = NULL) { + public function access($operation = 'view', AccountInterface $account = NULL) { // Determine the language code of this translation by cutting of the // leading "@" from the property name to get the langcode. // @todo Add a way to set and get the langcode so that's more obvious what diff --git a/core/lib/Drupal/Core/Entity/Field/Type/Field.php b/core/lib/Drupal/Core/Entity/Field/Type/Field.php index 5d0a4ff..40c6f6d 100644 --- a/core/lib/Drupal/Core/Entity/Field/Type/Field.php +++ b/core/lib/Drupal/Core/Entity/Field/Type/Field.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Entity\Field\Type; use Drupal\Core\Entity\Field\FieldInterface; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\ItemList; @@ -152,7 +152,7 @@ public function __unset($property_name) { /** * Implements \Drupal\Core\TypedData\AccessibleInterface::access(). */ - public function access($operation = 'view', User $account = NULL) { + public function access($operation = 'view', AccountInterface $account = NULL) { global $user; if (!isset($account) && $user->uid) { $account = user_load($user->uid); @@ -197,7 +197,7 @@ public function access($operation = 'view', User $account = NULL) { * @return bool * TRUE if access to this field is allowed per default, FALSE otherwise. */ - public function defaultAccess($operation = 'view', User $account = NULL) { + public function defaultAccess($operation = 'view', AccountInterface $account = NULL) { // Grant access per default. return TRUE; } diff --git a/core/lib/Drupal/Core/Session/AccountInterface.php b/core/lib/Drupal/Core/Session/AccountInterface.php new file mode 100644 index 0000000..1dbc13c --- /dev/null +++ b/core/lib/Drupal/Core/Session/AccountInterface.php @@ -0,0 +1,58 @@ + $value) { + $this->$key = $value; + } + } + + /** + * {@inheritdoc} + */ + public function id() { + return $this->uid; + } + + /** + * {@inheritdoc} + */ + public function getRoles() { + return $this->roles; + } + + /** + * {@inheritdoc} + */ + public function getSecureSessionId() { + return $this->ssid; + } + + /** + * {@inheritdoc} + */ + public function getSessionData() { + return $this->session; + } + + /** + * {@inheritdoc} + */ + public function getSessionId() { + return $this->sid; + } + +} diff --git a/core/lib/Drupal/Core/TypedData/AccessibleInterface.php b/core/lib/Drupal/Core/TypedData/AccessibleInterface.php index 1b0dacd..2676006 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\Core\Session\AccountInterface; + /** * Interface for checking access. */ @@ -22,7 +24,7 @@ * - update * - delete * Defaults to 'view'. - * @param \Drupal\user\Plugin\Core\Entity\User $account + * @param Drupal\Core\Session\AccountInterface $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. * @@ -32,6 +34,6 @@ * * @todo Don't depend on module level code. */ - public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $account = NULL); + public function access($operation = 'view', AccountInterface $account = NULL); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php index 69aee17..8ac282a 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php @@ -8,8 +8,8 @@ namespace Drupal\custom_block; use Drupal\Core\Entity\EntityInterface; -use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Entity\EntityAccessController; +use Drupal\Core\Session\AccountInterface; /** * Defines the access controller for the custom block entity type. @@ -19,7 +19,7 @@ class CustomBlockAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation === 'view') { return TRUE; } diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index 1675cc2..62ff637 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Provides a Block access controller. @@ -19,7 +19,7 @@ class BlockAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation === 'view') { return $entity->getPlugin()->access(); } diff --git a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php index b20d850..4749428 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentAccessController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Access controller for the comment entity. @@ -21,7 +21,7 @@ class CommentAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'view': return user_access('access comments', $account); diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index cee9228..fa2e8fb 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -7,10 +7,10 @@ namespace Drupal\node; -use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityNG; +use Drupal\Core\Session\AccountInterface; /** * Defines the access controller for the node entity type. @@ -20,7 +20,7 @@ class NodeAccessController extends EntityAccessController { /** * {@inheritdoc} */ - public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, AccountInterface $account = NULL) { if (user_access('bypass node access', $account)) { return TRUE; } @@ -33,7 +33,7 @@ public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $node, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $node, $operation, $langcode, AccountInterface $account) { // Fetch information from the node object if possible. $status = isset($node->status) ? $node->status : NULL; $uid = isset($node->uid) ? $node->uid : NULL; @@ -82,7 +82,7 @@ protected function checkAccess(EntityInterface $node, $operation, $langcode, Use * module implements hook_node_grants(), the node does not (yet) have an id * or none of the implementing modules explicitly granted or denied access. */ - protected function accessGrants(EntityInterface $node, $operation, $langcode, User $account) { + protected function accessGrants(EntityInterface $node, $operation, $langcode, AccountInterface $account) { // If no module implements the hook or the node does not have an id there is // no point in querying the database for access grants. if (!module_implements('node_grants') || !$node->id()) { diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php index b527b1f..0c6a2dd 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityAccessController; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines the access controller for the shortcut entity type. @@ -19,7 +19,7 @@ class ShortcutAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation == 'delete') { if (!user_access('administer shortcuts', $account)) { return FALSE; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php index c29e4f3..9733be6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php @@ -8,8 +8,8 @@ namespace Drupal\system\Tests\Entity; use Drupal\Core\Language\Language; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AccessibleInterface; -use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Entity\EntityAccessController; /** @@ -45,7 +45,7 @@ function setUp() { /** * Asserts entity access correctly grants or denies access. */ - function assertEntityAccess($ops, AccessibleInterface $object, User $account = NULL) { + function assertEntityAccess($ops, AccessibleInterface $object, AccountInterface $account = NULL) { foreach ($ops as $op => $result) { $message = format_string("Entity access returns @result with operation '@op'.", array( '@result' => !isset($result) ? 'null' : ($result ? 'true' : 'false'), diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php index 9da187d..e3c72c7 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityAccessController; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines the access controller for the test entity type. @@ -19,7 +19,7 @@ class EntityTestAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation === 'view') { if ($langcode != LANGUAGE_DEFAULT) { return user_access('view test entity translations', $account); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php index bd1cff8..d562e84 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines an access controller for the taxonomy term entity. @@ -21,7 +21,7 @@ class TermAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'view': return user_access('access content', $account); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php index bd02c30..0750593 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines an access controller for the vocabulary entity. @@ -21,7 +21,7 @@ class VocabularyAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { return user_access('administer taxonomy', $account); } 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 44c4562..9e3f73b 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 @@ -173,9 +173,38 @@ class User extends Entity implements UserInterface { public $roles = array(); /** - * Implements Drupal\Core\Entity\EntityInterface::id(). + * {@inheritdoc} */ public function id() { return $this->uid; } + + /** + * {@inheritdoc} + */ + public function getRoles() { + return $this->roles; + } + + /** + * {@inheritdoc} + */ + public function getSecureSessionId() { + return NULL; + } + + /** + * {@inheritdoc} + */ + public function getSessionData() { + return array(); + } + + /** + * {@inheritdoc} + */ + public function getSessionId() { + return NULL; + } + } diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php b/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php index 5b4004d..52b209d 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/access/Permission.php @@ -10,6 +10,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\views\Plugin\views\access\AccessPluginBase; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Access plugin that provides permission-based access control. @@ -29,7 +30,7 @@ class Permission extends AccessPluginBase { */ protected $usesOptions = TRUE; - public function access($account) { + public function access(AccountInterface $account) { return views_check_perm($this->options['perm'], $account); } diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php b/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php index 6448df4..a4ac6b4 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/access/Role.php @@ -10,6 +10,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\views\Plugin\views\access\AccessPluginBase; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; /** * Access plugin that provides role-based access control. @@ -29,7 +30,7 @@ class Role extends AccessPluginBase { */ protected $usesOptions = TRUE; - public function access($account) { + public function access(AccountInterface $account) { return views_check_roles(array_filter($this->options['role']), $account); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php index 15894ad..13f6489 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php @@ -33,7 +33,7 @@ function setUp() { parent::setUp(); $this->account = $this->drupalCreateUser(); - $this->anonymous = drupal_anonymous_user(); + $this->anonymous = entity_create('user', array('uid' => 0)); } /** diff --git a/core/modules/user/lib/Drupal/user/UserAccessController.php b/core/modules/user/lib/Drupal/user/UserAccessController.php index 4332fbc..119b533 100644 --- a/core/modules/user/lib/Drupal/user/UserAccessController.php +++ b/core/modules/user/lib/Drupal/user/UserAccessController.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityAccessController; -use Drupal\user\Plugin\Core\Entity\User; +use Drupal\Core\Session\AccountInterface; /** * Defines the access controller for the user entity type. @@ -19,7 +19,7 @@ class UserAccessController extends EntityAccessController { /** * {@inheritdoc} */ - protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { + protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { switch ($operation) { case 'view': return $this->viewAccess($entity, $langcode, $account); @@ -49,7 +49,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, U * * See EntityAccessControllerInterface::view() for parameters. */ - protected function viewAccess(EntityInterface $entity, $langcode, User $account) { + protected function viewAccess(EntityInterface $entity, $langcode, AccountInterface $account) { // Never allow access to view the anonymous user account. if ($entity->uid) { // Admins can view all, users can view own profiles at all times. diff --git a/core/modules/user/lib/Drupal/user/UserInterface.php b/core/modules/user/lib/Drupal/user/UserInterface.php index 99818a8..4775be4 100644 --- a/core/modules/user/lib/Drupal/user/UserInterface.php +++ b/core/modules/user/lib/Drupal/user/UserInterface.php @@ -8,10 +8,11 @@ namespace Drupal\user; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Session\AccountInterface; /** * Provides an interface defining a user entity. */ -interface UserInterface extends EntityInterface { +interface UserInterface extends EntityInterface, AccountInterface { } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 5f0b0f8..bc109a9 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -3,6 +3,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\comment\Plugin\Core\Entity\Comment; use Drupal\entity\Plugin\Core\Entity\EntityDisplay; use Drupal\file\Plugin\Core\Entity\File; @@ -469,7 +470,7 @@ function user_role_permissions($roles) { * * @param $string * The permission, such as "administer nodes", being checked for. - * @param $account + * @param \Drupal\Core\Session\AccountInterface $account * (optional) The account to check, if not given use currently logged in user. * * @return @@ -479,7 +480,7 @@ function user_role_permissions($roles) { * way, we guarantee consistent behavior, and ensure that the superuser * can perform all actions. */ -function user_access($string, $account = NULL) { +function user_access($string, AccountInterface $account = NULL) { global $user; if (!isset($account)) { @@ -500,7 +501,7 @@ function user_access($string, $account = NULL) { } $perm = &$drupal_static_fast['perm']; if (!isset($perm[$account->uid])) { - $role_permissions = user_role_permissions($account->roles); + $role_permissions = user_role_permissions($account->getRoles()); $perms = array(); foreach ($role_permissions as $one_role) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/access/AccessPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/access/AccessPluginBase.php index 0d70b4c..a1c87cb 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/access/AccessPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/access/AccessPluginBase.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\access; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\PluginBase; use Drupal\views\ViewExecutable; @@ -56,13 +57,13 @@ public function summaryTitle() { /** * Determine if the current user has access or not. * - * @param Drupal\user\User $account + * @param \Drupal\Core\Session\AccountInterface $account * The user who wants to access this view. * * @return TRUE * Returns whether the user has access to the view. */ - abstract public function access($account); + abstract public function access(AccountInterface $account); /** * Determine the access callback and arguments. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/access/None.php b/core/modules/views/lib/Drupal/views/Plugin/views/access/None.php index 55e1c80..c53afa1 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/access/None.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/access/None.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Component\Annotation\Plugin; +use Drupal\Core\Session\AccountInterface; /** * Access plugin that provides no access control at all. @@ -30,7 +31,7 @@ public function summaryTitle() { /** * Implements Drupal\views\Plugin\views\access\AccessPluginBase::access(). */ - public function access($account) { + public function access(AccountInterface $account) { // No access control. return TRUE; } diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/DynamicTest.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/DynamicTest.php index b153c93..f7348fc 100644 --- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/DynamicTest.php +++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/DynamicTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\access\AccessPluginBase; /** @@ -29,7 +30,7 @@ protected function defineOptions() { return $options; } - public function access($account) { + public function access(AccountInterface $account) { return !empty($this->options['access']) && isset($this->view->args[0]) && $this->view->args[0] == state()->get('test_dynamic_access_argument1') && isset($this->view->args[1]) && $this->view->args[1] == state()->get('test_dynamic_access_argument2'); } diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/StaticTest.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/StaticTest.php index 398e8d7..1206cdb 100644 --- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/StaticTest.php +++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/access/StaticTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\access\AccessPluginBase; /** @@ -29,7 +30,7 @@ protected function defineOptions() { return $options; } - public function access($account) { + public function access(AccountInterface $account) { return !empty($this->options['access']); } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index 5877f28..8bcd457 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -11,6 +11,7 @@ use Drupal\views\ViewExecutable; use Drupal\Core\Database\Database; use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\views\Plugin\views\query\Sql; use Drupal\views\Plugin\Core\Entity\View; use Drupal\views\ViewStorageInterface; @@ -942,7 +943,7 @@ public function language() { /** * Implements \Drupal\Core\TypedData\AccessibleInterface::access(). */ - public function access($operation = 'view', User $account = NULL) { + public function access($operation = 'view', AccountInterface $account = NULL) { return $this->storage->access($operation, $account); }