class CastedIntFieldJoin
Same name in other branches
- 10 core/modules/views/src/Plugin/views/join/CastedIntFieldJoin.php \Drupal\views\Plugin\views\join\CastedIntFieldJoin
Implementation for the "casted_int_field_join" join.
This is needed for columns that are using a single table for tracking the relationship to their items, but the referenced item IDs can be either integers or strings and most DB engines (with MySQL as a notable exception) are strict when comparing numbers and strings.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\views\Plugin\views\join\JoinPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\views\Plugin\views\join\JoinPluginInterface
- class \Drupal\views\Plugin\views\join\CastedIntFieldJoin extends \Drupal\views\Plugin\views\join\JoinPluginBase
- class \Drupal\views\Plugin\views\join\JoinPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\views\Plugin\views\join\JoinPluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of CastedIntFieldJoin
Related topics
1 file declares its use of CastedIntFieldJoin
- CastedIntFieldJoinTestBase.php in core/
modules/ views/ tests/ src/ Kernel/ Plugin/ CastedIntFieldJoinTestBase.php
File
-
core/
modules/ views/ src/ Plugin/ views/ join/ CastedIntFieldJoin.php, line 17
Namespace
Drupal\views\Plugin\views\joinView source
class CastedIntFieldJoin extends JoinPluginBase {
/**
* {@inheritdoc}
*/
public function buildJoin($select_query, $table, $view_query) {
if (empty($this->configuration['table formula'])) {
$right_table = $this->table;
}
else {
$right_table = $this->configuration['table formula'];
}
if ($this->leftTable) {
$left_table = $view_query->getTableInfo($this->leftTable);
$left_field = $this->leftFormula ?: "{$left_table['alias']}.{$this->leftField}";
}
else {
// This can be used if left_field is a formula or something. It should be
// used only *very* rarely.
$left_field = $this->leftField;
$left_table = NULL;
}
$right_field = "{$table['alias']}.{$this->field}";
assert(!isset($this->configuration['cast']) || in_array($this->configuration['cast'], [
'right',
'left',
]));
if (isset($this->configuration['cast']) && $this->configuration['cast'] === 'left') {
$left_field = \Drupal::service('views.cast_sql')->getFieldAsInt($left_field);
}
else {
$right_field = \Drupal::service('views.cast_sql')->getFieldAsInt($right_field);
}
$condition = "{$left_field} {$this->configuration['operator']} {$right_field}";
$arguments = [];
// Tack on the extra.
if (isset($this->extra)) {
$this->joinAddExtra($arguments, $condition, $table, $select_query, $left_table);
}
$select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
CastedIntFieldJoin::buildJoin | public | function | Overrides JoinPluginBase::buildJoin | ||
JoinPluginBase::$adjusted | public | property | Defines whether a join has been adjusted. | ||
JoinPluginBase::$configuration | public | property | The configuration array passed by initJoin. | ||
JoinPluginBase::$extra | public | property | An array of extra conditions on the join. | ||
JoinPluginBase::$extraOperator | public | property | How all the extras will be combined. Either AND or OR. | ||
JoinPluginBase::$field | public | property | The field to join on (right field). | ||
JoinPluginBase::$leftField | public | property | The field we join to. | ||
JoinPluginBase::$leftFormula | public | property | A formula to be used instead of the left field. | ||
JoinPluginBase::$leftTable | public | property | The table we join to. | ||
JoinPluginBase::$table | public | property | The table to join (right table). | ||
JoinPluginBase::$type | public | property | The join type, so for example LEFT (default) or INNER. | ||
JoinPluginBase::buildExtra | protected | function | Builds a single extra condition. | ||
JoinPluginBase::joinAddExtra | protected | function | Adds the extras to the join condition. | 1 | |
JoinPluginBase::__construct | public | function | Constructs a Drupal\views\Plugin\views\join\JoinPluginBase object. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.