public function DateRecurFilter::query in Recurring Dates Field 8.2
Same name and namespace in other branches
- 3.x src/Plugin/views/filter/DateRecurFilter.php \Drupal\date_recur\Plugin\views\filter\DateRecurFilter::query()
- 3.0.x src/Plugin/views/filter/DateRecurFilter.php \Drupal\date_recur\Plugin\views\filter\DateRecurFilter::query()
- 3.1.x src/Plugin/views/filter/DateRecurFilter.php \Drupal\date_recur\Plugin\views\filter\DateRecurFilter::query()
Add this filter to the query.
Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.
Overrides FilterPluginBase::query
File
- src/
Plugin/ views/ filter/ DateRecurFilter.php, line 132
Class
- DateRecurFilter
- Date range/occurrence filter.
Namespace
Drupal\date_recur\Plugin\views\filterCode
public function query() : void {
$this
->ensureMyTable();
$dateRecurFieldName = $this->configuration['date recur field name'];
$entityIdFieldName = $this->configuration['field base entity_id'];
$fieldDefinitions = $this->entityFieldManager
->getFieldStorageDefinitions($this->configuration['entity_type']);
$occurrenceTableName = DateRecurOccurrences::getOccurrenceCacheStorageTableName($fieldDefinitions[$dateRecurFieldName]);
$storageTimezone = new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE);
$storageFormat = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
$subQuery = $this->database
->select($occurrenceTableName, 'occurrences');
$subQuery
->addField('occurrences', 'entity_id');
$largestDate = $this->largestDate;
$largestDate
->setTimezone($storageTimezone);
$startFieldName = $dateRecurFieldName . '_value';
$subQuery
->condition($startFieldName, $largestDate
->format($storageFormat), '<=');
$smallestDate = $this->smallestDate;
$smallestDate
->setTimezone($storageTimezone);
$endFieldName = $dateRecurFieldName . '_end_value';
$subQuery
->condition($endFieldName, $smallestDate
->format($storageFormat), '>=');
$subQuery
->groupBy('entity_id');
$this->query
->addWhere(0, $this->tableAlias . '.' . $entityIdFieldName, $subQuery, 'IN');
}