How to add join condition in views programmatically in Drupal 8?
use $query->queueTable to implement joins.
function hook_views_query_alterViewExecutable $views, QueryPluginBase $query) {
$query->queueTable('node__field_accounts', "node_field_data", NULL, 'node__field_accounts');
$query->addWhere($where_last_key, 'node__field_accounts.field_accounts_target_id',
$account_values['target_id'], 'IN');
}
Method definition
Sql::queueTable($table, $relationship = NULL, JoinPluginBase $join = NULL, $alias = NULL)
To use INNER JOIN
$configuration = [
'type' => 'INNER',
'table' => 'user__field_region',
'field' => 'entity_id',
'left_table' => 'users_field_data',
'left_field' => 'uid',
'operator' => '=',
];
$join = Views::pluginManager('join')
->createInstance('standard', $configuration);
$query->queueTable('user__field_region', 'users_field_data', $join , 'user__field_region');
Comments
Post a Comment