Commit 88e6a760 authored by alexpott's avatar alexpott
Browse files

Issue #1818570 by Berdir, effulgentsia, das-peter, andypost: Convert users to...

Issue #1818570 by Berdir, effulgentsia, das-peter, andypost: Convert users to the new Entity Field API.
parent 6d93172b
......@@ -22,6 +22,7 @@
use Drupal\Core\Lock\DatabaseLockBackend;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\Core\Entity\EntityBCDecorator;
/**
* @file
......@@ -1760,18 +1761,15 @@ function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {
/**
* Generates a default anonymous $user object.
*
* @return Drupal\user\Plugin\Core\Entity\User
* @return object
* The user object.
*/
function drupal_anonymous_user() {
$values = array(
return (object) array(
'uid' => 0,
'hostname' => Drupal::request()->getClientIP(),
'roles' => array(
DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
),
'roles' => array(DRUPAL_ANONYMOUS_RID),
);
return new User($values, 'user');
}
/**
......
......@@ -5188,7 +5188,7 @@ function drupal_render_cid_parts($granularity = NULL) {
// resource drag for sites with many users, so when a module is being
// equivocal, we favor the less expensive 'PER_ROLE' pattern.
if ($granularity & DRUPAL_CACHE_PER_ROLE) {
$cid_parts[] = 'r.' . implode(',', array_keys($user->roles));
$cid_parts[] = 'r.' . implode(',', $user->roles);
}
elseif ($granularity & DRUPAL_CACHE_PER_USER) {
$cid_parts[] = "u.$user->uid";
......
......@@ -548,7 +548,7 @@ function hook_entity_field_info_alter(&$info, $entity_type) {
* \Drupal\Core\TypedData\AccessibleInterface::access() for possible values.
* @param \Drupal\Core\Entity\Field\Type\Field $field
* The entity field object on which the operation is to be performed.
* @param \Drupal\user\Plugin\Core\Entity\User $account
* @param \Drupal\user\UserInterface $account
* The user account to check.
*
* @return bool|NULL
......
......@@ -108,9 +108,8 @@ function _drupal_session_read($sid) {
// active user.
if ($user && $user->uid > 0 && $user->status == 1) {
// Add roles element to $user.
$user->roles = array();
$user->roles[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID;
$user->roles += db_query("SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = :uid", array(':uid' => $user->uid))->fetchAllKeyed(0, 0);
$rids = db_query("SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = :uid", array(':uid' => $user->uid))->fetchCol();
$user->roles = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids);
}
elseif ($user) {
// The user is anonymous or blocked. Only preserve two fields from the
......
......@@ -191,6 +191,8 @@ public function resetCache(array $ids = NULL) {
}
else {
$this->entityCache = array();
$this->entityFieldInfo = NULL;
$this->fieldDefinitions = array();
}
}
......
......@@ -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\Plugin\Core\Entity\User $account = NULL) {
public function access($operation = 'view', UserInterface $account = NULL) {
return \Drupal::entityManager()
->getAccessController($this->entityType)
->access($this, $operation, Language::LANGCODE_DEFAULT, $account);
......
......@@ -8,7 +8,7 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Language\Language;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
/**
* Defines a default implementation for entity access controllers.
......@@ -25,7 +25,7 @@ class EntityAccessController implements EntityAccessControllerInterface {
/**
* {@inheritdoc}
*/
public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) {
public function access(EntityInterface $entity, $operation, $langcode = Language::LANGUAGE_DEFAULT, UserInterface $account = NULL) {
// @todo Remove this once we can rely on $account.
if (!$account) {
......@@ -73,14 +73,14 @@ public function access(EntityInterface $entity, $operation, $langcode = Language
* 'delete'.
* @param string $langcode
* The language code for which to check access.
* @param \Drupal\user\Plugin\Core\Entity\User $account
* @param \Drupal\user\UserInterface $account
* The user for which to check access.
*
* @return bool|null
* 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, UserInterface $account) {
return NULL;
}
......@@ -94,7 +94,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, U
* 'delete'.
* @param string $langcode
* The language code for which to check access.
* @param \Drupal\user\Plugin\Core\Entity\User $account
* @param \Drupal\user\UserInterface $account
* The user for which to check access.
*
* @return bool|null
......@@ -102,7 +102,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, UserInterface $account) {
$uid = $account ? $account->id() : 0;
$uuid = $entity->uuid();
......@@ -122,13 +122,13 @@ protected function getCache(EntityInterface $entity, $operation, $langcode, User
* 'delete'.
* @param string $langcode
* The language code for which to check access.
* @param \Drupal\user\Plugin\Core\Entity\User $account
* @param \Drupal\user\UserInterface $account
* The user for which to check access.
*
* @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, UserInterface $account) {
$uid = $account ? $account->id() : 0;
$uuid = $entity->uuid();
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Language\Language;
// @todo Don't depend on module level code.
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
/**
* Defines a common interface for entity access controller classes.
......@@ -27,14 +27,14 @@ interface EntityAccessControllerInterface {
* @param string $langcode
* (optional) The language code for which to check access. Defaults to
* Language::LANGCODE_DEFAULT.
* @param \Drupal\user\Plugin\Core\Entity\User $account
* @param \Drupal\user\UserInterface $account
* (optional) The user 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::LANGCODE_DEFAULT, User $account = NULL);
public function access(EntityInterface $entity, $operation, $langcode = Language::LANGUAGE_DEFAULT, UserInterface $account = NULL);
/**
* Clears all cached access checks.
......
......@@ -11,6 +11,7 @@
use IteratorAggregate;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\user\UserInterface;
/**
* Provides backwards compatible (BC) access to entity fields.
......@@ -213,7 +214,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', UserInterface $account = NULL) {
return $this->decorated->access($operation, $account);
}
......
......@@ -10,6 +10,7 @@
use Drupal\Core\TypedData\AccessibleInterface;
use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\TypedData;
use Drupal\user\UserInterface;
use ArrayIterator;
use Drupal\Core\TypedData\TypedDataInterface;
use IteratorAggregate;
......@@ -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', UserInterface $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
......
......@@ -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\user\UserInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\ItemList;
......@@ -145,7 +145,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', UserInterface $account = NULL) {
global $user;
if (!isset($account) && $user->uid) {
$account = user_load($user->uid);
......@@ -190,7 +190,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', UserInterface $account = NULL) {
// Grant access per default.
return TRUE;
}
......
......@@ -7,6 +7,8 @@
namespace Drupal\Core\TypedData;
use Drupal\user\UserInterface;
/**
* Interface for checking access.
*/
......@@ -22,7 +24,7 @@ interface AccessibleInterface {
* - update
* - delete
* Defaults to 'view'.
* @param \Drupal\user\Plugin\Core\Entity\User $account
* @param \Drupal\user\UserInterface $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 @@ interface AccessibleInterface {
*
* @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', UserInterface $account = NULL);
}
......@@ -8,7 +8,7 @@
namespace Drupal\custom_block;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
use Drupal\Core\Entity\EntityAccessController;
/**
......@@ -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, UserInterface $account) {
if ($operation === 'view') {
return TRUE;
}
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
/**
* 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, UserInterface $account) {
// Currently, only view access is implemented.
if ($operation != 'view') {
return FALSE;
......@@ -43,7 +43,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, U
// For blocks with roles associated, if none of the user's roles matches
// the settings from this block, access is denied.
$visibility = $entity->get('visibility');
if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), array_keys($user->roles))) {
if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), $user->roles)) {
// No match.
return FALSE;
}
......
......@@ -1552,7 +1552,7 @@ function comment_prepare_author(Comment $comment) {
if (!$account) {
$account = entity_create('user', array('uid' => 0, 'name' => $comment->name->value, 'homepage' => $comment->homepage->value));
}
return $account;
return $account->getBCEntity();
}
/**
......
......@@ -218,7 +218,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
}
if (($author_tokens = $token_service->findwithPrefix($tokens, 'author')) && $account = $comment->uid->entity) {
$replacements += $token_service->generate('user', $author_tokens, array('user' => $account), $options);
$replacements += $token_service->generate('user', $author_tokens, array('user' => $account->getBCEntity()), $options);
}
}
elseif ($type == 'node' & !empty($data['node'])) {
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
/**
* 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, UserInterface $account) {
switch ($operation) {
case 'view':
return user_access('access comments', $account);
......
......@@ -52,7 +52,8 @@ function testCommentLinks() {
// Remove additional user permissions from $this->web_user added by setUp(),
// since this test is limited to anonymous and authenticated roles only.
entity_delete_multiple('user_role', array(key($this->web_user->roles)));
$roles = $this->web_user->roles;
entity_delete_multiple('user_role', array(reset($roles)));
// Matrix of possible environmental conditions and configuration settings.
// See setEnvironment() for details.
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
/**
* Defines an access controller for the contact category entity.
......@@ -21,7 +21,7 @@ class CategoryAccessController extends EntityAccessController {
/**
* {@inheritdoc}
*/
public function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) {
public function checkAccess(EntityInterface $entity, $operation, $langcode, UserInterface $account) {
if ($operation == 'delete' || $operation == 'update') {
// Do not allow delete 'personal' category used for personal contact form.
return user_access('administer contact forms', $account) && $entity->id() !== 'personal';
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityFormController;
use Drupal\Core\Language\Language;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
/**
* Form controller for contact message forms.
......@@ -167,7 +167,7 @@ public function save(array $form, array &$form_state) {
$to = implode(', ', $category->recipients);
$recipient_langcode = language_default()->langcode;
}
elseif ($message->recipient instanceof User) {
elseif ($message->recipient instanceof UserInterface) {
// Send to the user in the user's preferred language.
$to = $message->recipient->mail;
$recipient_langcode = user_preferred_langcode($message->recipient);
......@@ -211,7 +211,7 @@ public function save(array $form, array &$form_state) {
// To avoid false error messages caused by flood control, redirect away from
// the contact form; either to the contacted user account or the front page.
if ($message->recipient instanceof User && user_access('access user profiles')) {
if ($message->recipient instanceof UserInterface && user_access('access user profiles')) {
$uri = $message->recipient->uri();
$form_state['redirect'] = array($uri['path'], $uri['options']);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment