3 namespace Drupal\views\Plugin\views\argument;
5 use Drupal\views\Plugin\views\display\DisplayPluginBase;
6 use Drupal\views\ViewExecutable;
9 * Argument handler for simple formulae.
11 * Child classes of this object should implement summaryArgument, at least.
14 * - formula: The formula to use for this handler.
16 * @ingroup views_argument_handlers
18 * @ViewsArgument("formula")
20 class Formula extends ArgumentPluginBase {
22 public $formula = NULL;
27 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
28 parent::init($view, $display, $options);
30 if (!empty($this->definition['formula'])) {
31 $this->formula = $this->definition['formula'];
35 public function getFormula() {
36 return str_replace('***table***', $this->tableAlias, $this->formula);
40 * Build the summary query based on a formula
42 protected function summaryQuery() {
43 $this->ensureMyTable();
44 // Now that our table is secure, get our formula.
45 $formula = $this->getFormula();
48 $this->base_alias = $this->name_alias = $this->query->addField(NULL, $formula, $this->field);
49 $this->query->setCountField(NULL, $formula, $this->field);
51 return $this->summaryBasics(FALSE);
55 * Build the query based upon the formula
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;
63 $placeholder => $this->argument,
65 $this->query->addWhere(0, $formula, $placeholders, 'formula');