diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index be10f7f46f..6ac6fd9341 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -445,6 +445,7 @@ protected function defineOptions() { 'path' => ['default' => ''], 'absolute' => ['default' => FALSE], 'external' => ['default' => FALSE], + 'check_access' => ['default' => FALSE], 'replace_spaces' => ['default' => FALSE], 'path_case' => ['default' => 'none'], 'trim_whitespace' => ['default' => FALSE], @@ -769,6 +770,16 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ], ], ]; + $form['alter']['check_access'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Check access'), + '#default_value' => $this->options['alter']['check_access'], + '#states' => [ + 'visible' => [ + ':input[name="options[alter][make_link]"]' => ['checked' => TRUE], + ], + ], + ]; $form['alter']['external'] = [ '#type' => 'checkbox', '#title' => $this->t('External server URL'), @@ -1445,6 +1456,11 @@ protected function renderAsLink($alter, $text, $tokens) { } } + // Check if user has access to the URL. + if ($alter['check_access'] && !$alter['url']->access()) { + return $text; + } + $options = $alter['url']->getOptions() + $options; $path = $alter['url']->setOptions($options)->toUriString();