diff --git a/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php b/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php index 0a7b916..86d6f63 100644 --- a/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php +++ b/core/modules/contact/lib/Drupal/contact/Plugin/views/field/ContactLink.php @@ -30,6 +30,28 @@ class ContactLink extends Link { protected $accessManager; /** + * Current user object. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $currentUser; + + /** + * Gets the current active user. + * + * @todo: https://drupal.org/node/2105123 put this method in + * \Drupal\Core\Plugin\PluginBase instead. + * + * @return \Drupal\Core\Session\AccountInterface + */ + protected function currentUser() { + if (!$this->currentUser) { + $this->currentUser = \Drupal::currentUser(); + } + return $this->currentUser; + } + + /** * Constructs a ContactLink object. * * @param array $configuration @@ -88,7 +110,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { // Check access when we pull up the user account so we know // if the user has made the contact page available. - if (!$this->accessManager->checkNamedRoute('contact.personal_page', array('user' => $entity->id()))) { + if (!$this->accessManager->checkNamedRoute('contact.personal_page', array('user' => $entity->id()), $this->currentUser())) { return; }