HistoryUserTimestamp.php in Drupal 8
File
core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
View source
<?php
namespace Drupal\history\Plugin\views\filter;
use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
class HistoryUserTimestamp extends FilterPluginBase {
use UncacheableDependencyTrait;
public $no_operator = TRUE;
public function usesGroupBy() {
return FALSE;
}
public function buildExposeForm(&$form, FormStateInterface $form_state) {
parent::buildExposeForm($form, $form_state);
unset($form['expose']['required']);
unset($form['expose']['multiple']);
unset($form['expose']['remember']);
}
protected function valueForm(&$form, FormStateInterface $form_state) {
if ($form_state
->get('exposed')) {
if (isset($this->options['expose']['label'])) {
$label = $this->options['expose']['label'];
}
else {
$label = $this
->t('Has new content');
}
$form['value'] = [
'#type' => 'checkbox',
'#title' => $label,
'#default_value' => $this->value,
];
}
}
public function query() {
if (!\Drupal::currentUser()
->isAuthenticated()) {
return;
}
if (!empty($this->options['exposed']) && empty($this->value)) {
return;
}
$limit = REQUEST_TIME - HISTORY_READ_LIMIT;
$this
->ensureMyTable();
$field = "{$this->tableAlias}.{$this->realField}";
$node = $this->query
->ensureTable('node_field_data', $this->relationship);
$clause = '';
$clause2 = '';
if ($alias = $this->query
->ensureTable('comment_entity_statistics', $this->relationship)) {
$clause = "OR {$alias}.last_comment_timestamp > (***CURRENT_TIME*** - {$limit})";
$clause2 = "OR {$field} < {$alias}.last_comment_timestamp";
}
$this->query
->addWhereExpression($this->options['group'], "({$field} IS NULL AND ({$node}.changed > (***CURRENT_TIME*** - {$limit}) {$clause})) OR {$field} < {$node}.changed {$clause2}");
}
public function adminSummary() {
if (!empty($this->options['exposed'])) {
return $this
->t('exposed');
}
}
}