diff --git a/core/modules/user/lib/Drupal/user/Controller/UserController.php b/core/modules/user/lib/Drupal/user/Controller/UserController.php index 4ac896a..eb1dbde 100644 --- a/core/modules/user/lib/Drupal/user/Controller/UserController.php +++ b/core/modules/user/lib/Drupal/user/Controller/UserController.php @@ -8,13 +8,14 @@ namespace Drupal\user\Controller; use Drupal\user\Form\UserLoginForm; +use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; /** * Controller routines for user routes. */ -class UserController { +class UserController extends ContainerAware { /** * Returns the user page. @@ -35,7 +36,7 @@ public function userPage(Request $request) { $response = new RedirectResponse(url('user/' . $user->uid, array('absolute' => TRUE))); } else { - $response = drupal_get_form(UserLoginForm::create(\Drupal::getContainer()), $request); + $response = drupal_get_form(UserLoginForm::create($this->container), $request); } return $response; } diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php index 2aa43f0..0cc09b7 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserLoginBlock.php @@ -10,7 +10,11 @@ use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\user\Form\UserLoginForm; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Provides a 'User login' block. @@ -21,7 +25,55 @@ * module = "user" * ) */ -class UserLoginBlock extends BlockBase { +class UserLoginBlock extends BlockBase implements ContainerFactoryPluginInterface { + + /** + * The DI Container. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * The request object. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** + * Constructs a new UserLoginBlock. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The DI Container. + * @param \Symfony\Component\HttpFoundation\Request $request + * The request object. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ContainerInterface $container, Request $request) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->container = $container; + $this->request = $request; + } + + /** + * {@inheritdo} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container, + $container->get('request') + ); + } /** * Overrides \Drupal\block\BlockBase::access(). @@ -34,7 +86,7 @@ public function access() { * {@inheritdoc} */ public function build() { - $form = drupal_get_form(UserLoginForm::create(\Drupal::getContainer()), \Drupal::request()); + $form = drupal_get_form(UserLoginForm::create($this->container), $this->request); unset($form['name']['#attributes']['autofocus']); unset($form['name']['#description']); unset($form['pass']['#description']);