View source
<?php
namespace Drupal\social_event\Plugin\views\filter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views\Views;
class EventEnrolledOrCreated extends FilterPluginBase {
public function adminSummary() {
}
protected function operatorForm(&$form, FormStateInterface $form_state) {
}
public function canExpose() {
return FALSE;
}
public function query() {
$account_profile = \Drupal::routeMatch()
->getParameter('user');
if (!is_null($account_profile) && is_object($account_profile)) {
$account_profile = $account_profile
->id();
}
$configuration = [
'table' => 'event_enrollment__field_event',
'field' => 'field_event_target_id',
'left_table' => 'node_field_data',
'left_field' => 'nid',
'operator' => '=',
];
$join = Views::pluginManager('join')
->createInstance('standard', $configuration);
$this->query
->addRelationship('event_enrollment__field_event', $join, 'node_field_data');
$configuration = [
'table' => 'event_enrollment_field_data',
'field' => 'id',
'left_table' => 'event_enrollment__field_event',
'left_field' => 'entity_id',
'operator' => '=',
];
$join = Views::pluginManager('join')
->createInstance('standard', $configuration);
$this->query
->addRelationship('event_enrollment_field_data', $join, 'node_field_data');
$configuration = [
'table' => 'event_enrollment__field_enrollment_status',
'field' => 'entity_id',
'left_table' => 'event_enrollment__field_event',
'left_field' => 'entity_id',
'operator' => '=',
];
$join = Views::pluginManager('join')
->createInstance('standard', $configuration);
$this->query
->addRelationship('event_enrollment__field_enrollment_status', $join, 'node_field_data');
$or_condition = db_or();
$event_creator = db_and();
$event_creator
->condition('node_field_data.uid', $account_profile, '=');
$event_creator
->condition('node_field_data.type', 'event', '=');
$or_condition
->condition($event_creator);
$enrolled_to_event = db_and();
$enrolled_to_event
->condition('event_enrollment_field_data.user_id', $account_profile, '=');
$enrolled_to_event
->condition('event_enrollment__field_enrollment_status.field_enrollment_status_value', '1', '=');
$or_condition
->condition($enrolled_to_event);
$this->query
->addWhere('enrolled_or_created', $or_condition);
}
public function getCacheContexts() {
$cache_contexts = parent::getCacheContexts();
if (!in_array('url', $cache_contexts)) {
$cache_contexts[] = 'url';
}
return $cache_contexts;
}
}