Commit 21226ab1 authored by webchick's avatar webchick

Issue #2001044 by alexander.ilivanov, ebeyrent, DmitryDrozdik, jlbellido,...

Issue #2001044 by alexander.ilivanov, ebeyrent, DmitryDrozdik, jlbellido, aitiba, alexpott, alvar0hurtad0, ayelet_Cr: Replace drupal_container() with Drupal::service() in the user module.
parent 58bcfb71
......@@ -13,6 +13,7 @@
use Drupal\views\ViewExecutable;
use Drupal\user\UserDataInterface;
use Drupal\Component\Annotation\PluginID;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides access to the user data service.
......@@ -33,12 +34,19 @@ class UserData extends FieldPluginBase {
protected $userData;
/**
* Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::init().
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('user.data'));
}
/**
* Constructs a UserData object.
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
public function __construct(array $configuration, $plugin_id, array $plugin_definition, UserDataInterface $user_data) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->userData = drupal_container()->get('user.data');
$this->userData = $user_data;
}
/**
......
......@@ -72,7 +72,7 @@ function testUserCancelUid1() {
$password = user_password();
$account = array(
'name' => 'user1',
'pass' => drupal_container()->get('password')->hash(trim($password)),
'pass' => $this->container->get('password')->hash(trim($password)),
);
// We cannot use $account->save() here, because this would result in the
// password being hashed again.
......
......@@ -107,7 +107,7 @@ function testPasswordRehashOnLogin() {
$default_count_log2 = 16;
// Retrieve instance of password hashing algorithm
$password_hasher = drupal_container()->get('password');
$password_hasher = $this->container->get('password');
// Create a new user and authenticate.
$account = $this->drupalCreateUser(array());
......
......@@ -597,7 +597,7 @@ function user_validate_current_pass(&$form, &$form_state) {
// that prevent them from being empty if they are changed.
$current_value = $account->getPropertyDefinition($key) ? $account->get($key)->value : $account->$key;
if ((strlen(trim($form_state['values'][$key])) > 0) && ($form_state['values'][$key] != $current_value)) {
$current_pass_failed = empty($form_state['values']['current_pass']) || !drupal_container()->get('password')->check($form_state['values']['current_pass'], $account);
$current_pass_failed = empty($form_state['values']['current_pass']) || !Drupal::service('password')->check($form_state['values']['current_pass'], $account);
if ($current_pass_failed) {
form_set_error('current_pass', t("Your current password is missing or incorrect; it's required to change the %name.", array('%name' => $name)));
form_set_error($key);
......@@ -1100,7 +1100,7 @@ function user_authenticate($name, $password) {
if (!empty($name) && !empty($password)) {
$account = user_load_by_name($name);
if ($account) {
$password_hasher = drupal_container()->get('password');
$password_hasher = Drupal::service('password');
if ($password_hasher->check($password, $account)) {
// Successful authentication.
$uid = $account->id();
......@@ -2002,7 +2002,7 @@ function user_modules_installed($modules) {
*/
function user_modules_uninstalled($modules) {
// Remove any potentially orphan module data stored for users.
drupal_container()->get('user.data')->delete($modules);
Drupal::service('user.data')->delete($modules);
}
/**
......
......@@ -304,7 +304,7 @@ function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') {
$current = REQUEST_TIME;
// Basic validation of arguments.
$account_data = drupal_container()->get('user.data')->get('user', $account->id());
$account_data = Drupal::service('user.data')->get('user', $account->id());
if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
// Validate expiration and hashed password/login.
if ($timestamp <= $current && $current - $timestamp < $timeout && $account->id() && $timestamp >= $account->getLastLoginTime() && $hashed_pass == user_pass_rehash($account->getPassword(), $timestamp, $account->getLastLoginTime())) {
......
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