Formula.php in Drupal 10
File
core/modules/views/src/Plugin/views/argument/Formula.php
View source
<?php
namespace Drupal\views\Plugin\views\argument;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
class Formula extends ArgumentPluginBase {
public $formula = NULL;
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
if (!empty($this->definition['formula'])) {
$this->formula = $this->definition['formula'];
}
}
public function getFormula() {
return str_replace('***table***', $this->tableAlias, $this->formula);
}
protected function summaryQuery() {
$this
->ensureMyTable();
$formula = $this
->getFormula();
$this->base_alias = $this->name_alias = $this->query
->addField(NULL, $formula, $this->field);
$this->query
->setCountField(NULL, $formula, $this->field);
return $this
->summaryBasics(FALSE);
}
public function query($group_by = FALSE) {
$this
->ensureMyTable();
$placeholder = $this
->placeholder();
$formula = $this
->getFormula() . ' = ' . $placeholder;
$placeholders = [
$placeholder => $this->argument,
];
$this->query
->addWhere(0, $formula, $placeholders, 'formula');
}
}
Classes
Name |
Description |
Formula |
Argument handler for simple formulae. |