Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / src / Plugin / views / field / UncacheableFieldHandlerTrait.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\field;
4
5 use Drupal\views\ResultRow;
6
7 /**
8  * Trait encapsulating the logic for uncacheable field handlers.
9  */
10 trait UncacheableFieldHandlerTrait {
11
12   /**
13    * {@inheritdoc}
14    *
15    * @see \Drupal\views\Plugin\views\Field\FieldHandlerInterface::render()
16    */
17   public function render(ResultRow $row) {
18     return $this->getFieldTokenPlaceholder();
19   }
20
21   /**
22    * {@inheritdoc}
23    *
24    * @see \Drupal\views\Plugin\views\Field\FieldHandlerInterface::postRender()
25    */
26   public function postRender(ResultRow $row, $output) {
27     $placeholder = $this->getFieldTokenPlaceholder();
28     $value = $this->doRender($row);
29     $this->last_render = str_replace($placeholder, $value, $output);
30     return [$placeholder => $value];
31   }
32
33   /**
34    * {@inheritdoc}
35    *
36    * @see \Drupal\views\Plugin\views\Field\FieldPluginBase::getFieldTokenPlaceholder()
37    */
38   abstract protected function getFieldTokenPlaceholder();
39
40   /**
41    * Actually renders the field markup.
42    *
43    * @param \Drupal\views\ResultRow $row
44    *   A result row.
45    *
46    * @return string
47    *   The field markup.
48    */
49   protected function doRender(ResultRow $row) {
50     return $this->getValue($row);
51   }
52
53   /**
54    * {@inheritdoc}
55    *
56    * @see \Drupal\views\Plugin\views\Field\FieldHandlerInterface::getValue()
57    */
58   abstract protected function getValue(ResultRow $row, $field = NULL);
59
60 }