Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / node / src / Plugin / views / field / RevisionLink.php
1 <?php
2
3 namespace Drupal\node\Plugin\views\field;
4
5 use Drupal\Core\Url;
6 use Drupal\views\Plugin\views\field\LinkBase;
7 use Drupal\views\ResultRow;
8
9 /**
10  * Field handler to present a link to a node revision.
11  *
12  * @ingroup views_field_handlers
13  *
14  * @ViewsField("node_revision_link")
15  */
16 class RevisionLink extends LinkBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function getUrlInfo(ResultRow $row) {
22     /** @var \Drupal\node\NodeInterface $node */
23     $node = $this->getEntity($row);
24     // Current revision uses the node view path.
25     return !$node->isDefaultRevision() ?
26       Url::fromRoute('entity.node.revision', ['node' => $node->id(), 'node_revision' => $node->getRevisionId()]) :
27       $node->urlInfo();
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function renderLink(ResultRow $row) {
34     /** @var \Drupal\node\NodeInterface $node */
35     $node = $this->getEntity($row);
36     if (!$node->getRevisionid()) {
37       return '';
38     }
39     $text = parent::renderLink($row);
40     $this->options['alter']['query'] = $this->getDestinationArray();
41     return $text;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   protected function getDefaultLabel() {
48     return $this->t('View');
49   }
50
51 }