Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views / src / Plugin / views / argument / Formula.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\argument;
4
5 use Drupal\views\Plugin\views\display\DisplayPluginBase;
6 use Drupal\views\ViewExecutable;
7
8 /**
9  * Argument handler for simple formulae.
10  *
11  * Child classes of this object should implement summaryArgument, at least.
12  *
13  * Definition terms:
14  * - formula: The formula to use for this handler.
15  *
16  * @ingroup views_argument_handlers
17  *
18  * @ViewsArgument("formula")
19  */
20 class Formula extends ArgumentPluginBase {
21
22   public $formula = NULL;
23
24   /**
25    * {@inheritdoc}
26    */
27   public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
28     parent::init($view, $display, $options);
29
30     if (!empty($this->definition['formula'])) {
31       $this->formula = $this->definition['formula'];
32     }
33   }
34
35   public function getFormula() {
36     return str_replace('***table***', $this->tableAlias, $this->formula);
37   }
38
39   /**
40    * Build the summary query based on a formula
41    */
42   protected function summaryQuery() {
43     $this->ensureMyTable();
44     // Now that our table is secure, get our formula.
45     $formula = $this->getFormula();
46
47     // Add the field.
48     $this->base_alias = $this->name_alias = $this->query->addField(NULL, $formula, $this->field);
49     $this->query->setCountField(NULL, $formula, $this->field);
50
51     return $this->summaryBasics(FALSE);
52   }
53
54   /**
55    * Build the query based upon the formula
56    */
57   public function query($group_by = FALSE) {
58     $this->ensureMyTable();
59     // Now that our table is secure, get our formula.
60     $placeholder = $this->placeholder();
61     $formula = $this->getFormula() . ' = ' . $placeholder;
62     $placeholders = [
63       $placeholder => $this->argument,
64     ];
65     $this->query->addWhere(0, $formula, $placeholders, 'formula');
66   }
67
68 }