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 e1943d5..851a450 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 @@ -7,10 +7,14 @@ namespace Drupal\contact\Plugin\views\field; -use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Annotation\PluginID; +use Drupal\Core\Access\StaticAccessCheckInterface; +use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Routing\RouteProviderInterface; use Drupal\user\Plugin\views\field\Link; use Drupal\views\ResultRow; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Defines a field that links to the user contact page, if access is permitted. @@ -22,6 +26,53 @@ class ContactLink extends Link { /** + * The access manager for contact_personal_page route. + * + * @var \Drupal\Core\Access\StaticAccessCheckInterface + */ + protected $accessManager; + + /** + * The router provider interface. + * + * @var \Drupal\Core\Routing\RouteProviderInterface + */ + protected $routeProvider; + + /** + * Constructs a Drupal\Component\Plugin\PluginBase object. + * + * @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 \Drupal\Core\Access\StaticAccessCheckInterface $access_manager + * The access manager for contact_personal_page route. + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider + * The router provider interface. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, StaticAccessCheckInterface $access_manager, RouteProviderInterface $route_provider) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->accessManager = $access_manager; + $this->routeProvider = $route_provider; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('access_check.contact_personal'), + $container->get('router.route_provider') + ); + } + + /** * {@inheritdoc} */ public function buildOptionsForm(&$form, &$form_state) { @@ -54,7 +105,10 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $uid = $entity->id(); $path = "user/$uid/contact"; - if (!_contact_personal_tab_access($entity)) { + $request = Request::create($path); + $request->attributes->set('user', $entity); + $route = $this->routeProvider->getRouteByName('contact_personal_page'); + if ($this->accessManager->access($route, $request) !== StaticAccessCheckInterface::ALLOW) { return; }