View source
<?php
namespace Drupal\farm_ui_views\Plugin\views\argument;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Drupal\views\Views;
class AssetOrLocationArgument extends ArgumentPluginBase {
public function query($group_by = FALSE) {
$this
->ensureMyTable();
$join = Views::pluginManager('join')
->createInstance('standard', [
'table' => 'log__asset',
'field' => 'entity_id',
'left_table' => $this->table,
'left_field' => 'id',
'extra' => [
[
'field' => 'deleted',
'value' => 0,
],
[
'field' => 'asset_target_id',
'value' => $this->argument,
],
],
]);
$asset_alias = $this->query
->addRelationship('log__asset', $join, $this->table);
$join = Views::pluginManager('join')
->createInstance('standard', [
'table' => 'log__location',
'field' => 'entity_id',
'left_table' => $this->table,
'left_field' => 'id',
'extra' => [
[
'field' => 'deleted',
'value' => 0,
],
[
'field' => 'location_target_id',
'value' => $this->argument,
],
],
]);
$location_alias = $this->query
->addRelationship('log__location', $join, $this->table);
$asset_condition = "{$asset_alias}.asset_target_id IS NOT NULL";
$location_condition = "{$location_alias}.location_target_id IS NOT NULL";
$this->query
->addWhereExpression(0, "{$this->table}.id IS NOT NULL AND ({$asset_condition} OR {$location_condition})");
}
}