3 namespace Drupal\node\Plugin\views\field;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\field\FieldPluginBase;
7 use Drupal\views\Plugin\views\display\DisplayPluginBase;
8 use Drupal\views\ResultRow;
9 use Drupal\views\ViewExecutable;
12 * Field handler to present the path to the node.
14 * @ingroup views_field_handlers
16 * @ViewsField("node_path")
18 class Path extends FieldPluginBase {
23 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
24 parent::init($view, $display, $options);
26 $this->additional_fields['nid'] = 'nid';
32 protected function defineOptions() {
33 $options = parent::defineOptions();
34 $options['absolute'] = ['default' => FALSE];
42 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
43 parent::buildOptionsForm($form, $form_state);
45 '#type' => 'checkbox',
46 '#title' => $this->t('Use absolute link (begins with "http://")'),
47 '#default_value' => $this->options['absolute'],
48 '#description' => $this->t('Enable this option to output an absolute link. Required if you want to use the path as a link destination (as in "output this field as a link" above).'),
49 '#fieldset' => 'alter',
56 public function query() {
57 $this->ensureMyTable();
58 $this->addAdditionalFields();
64 public function render(ResultRow $values) {
65 $nid = $this->getValue($values, 'nid');
67 '#markup' => \Drupal::url('entity.node.canonical', ['node' => $nid], ['absolute' => $this->options['absolute']]),