Commit 7cf239e3 authored by Mario Steinitz's avatar Mario Steinitz Committed by Mario Steinitz
Browse files

Issue #2960884 by Mario Steinitz: Use dependency injection instead of global getters

parent 56cf034f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ services:

  openid_connect.authmap:
    class: Drupal\openid_connect\Authmap
    arguments: ["@database"]
    arguments: ["@database", "@entity_type.manager"]

  openid_connect.claims:
    class: Drupal\openid_connect\Claims
+16 −5
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
namespace Drupal\openid_connect;

use Drupal\Core\Database\Connection;
use Drupal\user\Entity\User;
use Drupal\Core\Entity\EntityTypeManagerInterface;

/**
 * Class Authmap.
 * The OpenID Connect authmap service.
 *
 * @package Drupal\openid_connect
 */
@@ -20,13 +20,23 @@ class Authmap {
  protected $connection;

  /**
   * Constructs a Authmap object.
   * The User entity storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $userStorage;

  /**
   * Constructs a OpenIDConnectAuthmap service object.
   *
   * @param \Drupal\Core\Database\Connection $connection
   *   A database connection.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity manager.
   */
  public function __construct(Connection $connection) {
  public function __construct(Connection $connection, EntityTypeManagerInterface $entity_type_manager) {
    $this->connection = $connection;
    $this->userStorage = $entity_type_manager->getStorage('user');
  }

  /**
@@ -85,7 +95,8 @@ class Authmap {
      ->condition('sub', $sub, '=')
      ->execute();
    foreach ($result as $record) {
      $account = User::load($record->uid);
      /* @var \Drupal\user\Entity\User $account */
      $account = $this->userStorage->load($record->uid);
      if (is_object($account)) {
        return $account;
      }
+5 −6
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ class RedirectController extends ControllerBase implements AccessInterface {
    LoggerChannelFactoryInterface $logger_factory,
    AccountInterface $current_user
  ) {

    $this->pluginManager = $plugin_manager;
    $this->requestStack = $request_stack;
    $this->loggerFactory = $logger_factory;
@@ -169,7 +168,7 @@ class RedirectController extends ControllerBase implements AccessInterface {
        if ($parameters['op'] === 'login') {
          $success = openid_connect_complete_authorization($client, $tokens, $destination);

          $register = \Drupal::config('user.settings')->get('register');
          $register = $this->config('user.settings')->get('register');
          if (!$success && $register !== USER_REGISTER_ADMINISTRATORS_ONLY) {
            drupal_set_message(t('Logging in with @provider could not be completed due to an error.', $provider_param), 'error');
          }