diff --git a/core/modules/contact/lib/Drupal/contact/Access/ContactPageAccess.php b/core/modules/contact/lib/Drupal/contact/Access/ContactPageAccess.php index c278349..0fbe32f 100644 --- a/core/modules/contact/lib/Drupal/contact/Access/ContactPageAccess.php +++ b/core/modules/contact/lib/Drupal/contact/Access/ContactPageAccess.php @@ -63,7 +63,7 @@ public function access(Route $route, Request $request) { return static::DENY; } - $current_account = $request->attributes->get('_account'); + $current_account = \Drupal::currentUser(); // Users may not contact themselves. if ($current_account->id() == $contact_account->id()) { diff --git a/core/modules/contact/lib/Drupal/contact/Controller/ContactPageController.php b/core/modules/contact/lib/Drupal/contact/Controller/ContactPageController.php index 3bc2e26..8e4059b 100644 --- a/core/modules/contact/lib/Drupal/contact/Controller/ContactPageController.php +++ b/core/modules/contact/lib/Drupal/contact/Controller/ContactPageController.php @@ -8,13 +8,11 @@ namespace Drupal\contact\Controller; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Entity\EntityManager; use Drupal\Core\Flood\FloodInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\contact\Plugin\Core\Entity\Category; use Drupal\user\UserInterface; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -22,7 +20,7 @@ /** * Controller routines for contact routes. */ -class ContactPageController extends ControllerBase { +class ContactPageController extends ControllerBase implements ContainerInjectionInterface { /** * The flood service. @@ -39,35 +37,21 @@ class ContactPageController extends ControllerBase { protected $contactSettings; /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManager - */ - protected $entityManager; - - /** - * Contact Storage Controller. - * - * @var \Drupal\Core\Entity\EntityStorageControllerInterface; - */ - protected $contactStorage; - - /** - * The URL generator. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** * Constructs a ContactController object. */ public function __construct() { $this->flood = $this->container->get('flood'); $this->contactSettings = $this->container->get('config.factory')->get('contact.settings'); - $this->entityManager = $this->container->get('plugin.manager.entity'); - $this->contactStorage = $this->entityManager->getStorageController('contact_category'); - $this->urlGenerator = $this->container->get('url_generator'); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('flood'), + $container->get('config.factory') + ); } /** @@ -94,12 +78,12 @@ public function contactSitePage(AccountInterface $_account, Category $contact_ca // Use the default category if no category has been passed. if (empty($contact_category)) { $default_category = $this->contactSettings->get('default_category'); - $contact_category = $this->contactStorage->load($default_category); + $contact_category = $this->entityManager()->getStorageController('contact_category')->load($default_category); // If there are no categories, do not display the form. if (empty($contact_category)) { if ($_account->hasPermission('administer contact forms')) { drupal_set_message($this->t('The contact form has not been configured. Add one or more categories to the form.', array( - '@add' => $this->urlGenerator->generateFromPath('admin/structure/contact/add'))), 'error'); + '@add' => $this->urlGenerator()->generateFromPath('admin/structure/contact/add'))), 'error'); return array(); } else { @@ -108,11 +92,11 @@ public function contactSitePage(AccountInterface $_account, Category $contact_ca } } - $message = $this->contactStorage->create(array( + $message = $this->entityManager()->getStorageController('contact_category')->create(array( 'category' => $contact_category->id(), )); - return $this->entityManager->getForm($message); + return $this->entityManager()->getForm($message); } /** @@ -132,12 +116,12 @@ public function contactPersonalPage(UserInterface $user, AccountInterface $_acco $this->contactFloodControl(); } - $message = $this->contactStorage->create(array( + $message = $this->entityManager()->getStorageController('contact_category')->create(array( 'category' => 'personal', 'recipient' => $user->id(), )); - $form = $this->entityManager->getForm($message); + $form = $this->entityManager()->getForm($message); $form['#title'] = $this->t('Contact @username', array('@username' => $user->getUsername())); return $form; }