public function CastedFieldJoin::buildJoin in Entityqueue 8
Builds the SQL for the join this object represents.
When possible, try to use table alias instead of table names.
Parameters
$select_query: An select query object.
$table: The base table to join.
\Drupal\views\Plugin\views\query\QueryPluginBase $view_query: The source views query.
Overrides JoinPluginBase::buildJoin
File
- src/
Plugin/ views/ join/ CastedFieldJoin.php, line 25
Class
- CastedFieldJoin
- Implementation for the "casted_field_join" join.
Namespace
Drupal\entityqueue\Plugin\views\joinCode
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 = "{$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}";
// Determine whether the left field of the relationship is an integer so we
// know whether a CAST() is needed for the right field.
if (isset($this->configuration['entity_type'])) {
$field_storage_definition = \Drupal::service('entity_field.manager')
->getFieldStorageDefinitions($this->configuration['entity_type'])[$this->leftField];
if (is_a($field_storage_definition
->getItemDefinition()
->getClass(), IntegerItem::class, TRUE)) {
switch (\Drupal::database()
->databaseType()) {
case 'mysql':
$cast_data_type = 'UNSIGNED';
break;
default:
$cast_data_type = 'INTEGER';
break;
}
$right_field = "CAST({$right_field} AS {$cast_data_type})";
}
}
$condition = "{$left_field} = {$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);
}