class Formula
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/argument/Formula.php \Drupal\views\Plugin\views\argument\Formula
Argument handler for simple formulae.
Child classes of this object should implement summaryArgument, at least.
Definition terms:
- formula: The formula to use for this handler.
Plugin annotation
@ViewsArgument("formula");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\argument\ArgumentPluginBase extends \Drupal\Core\Cache\CacheableDependencyInterface implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\argument\Formula implements \Drupal\views\Plugin\views\argument\ArgumentPluginBase
- class \Drupal\views\Plugin\views\argument\ArgumentPluginBase extends \Drupal\Core\Cache\CacheableDependencyInterface implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of Formula
Related topics
5 string references to 'Formula'
- Formula::query in core/
modules/ views/ src/ Plugin/ views/ argument/ Formula.php - Build the query based upon the formula.
- Sql::addHavingExpression in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Add a complex HAVING clause to the query.
- Sql::addWhereExpression in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Adds a complex WHERE clause to the query.
- Sql::buildCondition in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Construct the "WHERE" or "HAVING" part of the query.
- views.argument.schema.yml in core/
modules/ views/ config/ schema/ views.argument.schema.yml - core/modules/views/config/schema/views.argument.schema.yml
File
-
core/
modules/ views/ src/ Plugin/ views/ argument/ Formula.php, line 20
Namespace
Drupal\views\Plugin\views\argumentView source
class Formula extends ArgumentPluginBase {
public $formula = NULL;
/**
* {@inheritdoc}
*/
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);
}
/**
* Build the summary query based on a formula.
*/
protected function summaryQuery() {
$this->ensureMyTable();
// Now that our table is secure, get our formula.
$formula = $this->getFormula();
// Add the field.
$this->base_alias = $this->name_alias = $this->query
->addField(NULL, $formula, $this->field);
$this->query
->setCountField(NULL, $formula, $this->field);
return $this->summaryBasics(FALSE);
}
/**
* Build the query based upon the formula.
*/
public function query($group_by = FALSE) {
$this->ensureMyTable();
// Now that our table is secure, get our formula.
$placeholder = $this->placeholder();
$formula = $this->getFormula() . ' = ' . $placeholder;
$placeholders = [
$placeholder => $this->argument,
];
$this->query
->addWhere(0, $formula, $placeholders, 'formula');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.