diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 8030f8860a..681f46e588 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], @@ -763,6 +764,16 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ], ], ]; + $form['alter']['check_access'] = [ + '#type' => 'checkbox', + '#title' => $this->t('URL access check'), + '#default_value' => $this->options['alter']['check_access'], + '#states' => [ + 'visible' => [ + ':input[name="options[alter][make_link]"]' => ['checked' => TRUE], + ], + ], + ]; $form['alter']['replace_spaces'] = [ '#type' => 'checkbox', '#title' => $this->t('Replace spaces with dashes'), @@ -1571,6 +1582,11 @@ protected function renderAsLink($alter, $text, $tokens) { // The path has been heavily processed above, so it should be used as-is. $final_url = CoreUrl::fromUri($path, $options); + // URL access check. + if ($alter['check_access'] && !empty($final_url) && !$final_url->access()) { + return ''; + } + // Build the link based on our altered Url object, adding on the optional // prefix and suffix $render = [