f9f6cf820b7e6d5f3b10d8990e8281359c8285a6
[yaffs-website] / web / core / modules / node / src / Plugin / views / field / Path.php
1 <?php
2
3 namespace Drupal\node\Plugin\views\field;
4
5 @trigger_error('Drupal\node\Plugin\views\field\Path is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use @ViewsField("entity_link") with \'output_url_as_text\' set.', E_USER_DEPRECATED);
6
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\views\Plugin\views\field\FieldPluginBase;
9 use Drupal\views\Plugin\views\display\DisplayPluginBase;
10 use Drupal\views\ResultRow;
11 use Drupal\views\ViewExecutable;
12
13 /**
14  * Field handler to present the path to the node.
15  *
16  * @ingroup views_field_handlers
17  *
18  * @ViewsField("node_path")
19  *
20  * @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0.
21  *  Use @ViewsField("entity_link") with 'output_url_as_text' set.
22  */
23 class Path extends FieldPluginBase {
24
25   /**
26    * {@inheritdoc}
27    */
28   public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
29     parent::init($view, $display, $options);
30
31     $this->additional_fields['nid'] = 'nid';
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function defineOptions() {
38     $options = parent::defineOptions();
39     $options['absolute'] = ['default' => FALSE];
40
41     return $options;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
48     parent::buildOptionsForm($form, $form_state);
49     $form['absolute'] = [
50       '#type' => 'checkbox',
51       '#title' => $this->t('Use absolute link (begins with "http://")'),
52       '#default_value' => $this->options['absolute'],
53       '#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).'),
54       '#fieldset' => 'alter',
55     ];
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function query() {
62     $this->ensureMyTable();
63     $this->addAdditionalFields();
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function render(ResultRow $values) {
70     $nid = $this->getValue($values, 'nid');
71     return [
72       '#markup' => \Drupal::url('entity.node.canonical', ['node' => $nid], ['absolute' => $this->options['absolute']]),
73     ];
74   }
75
76 }