ViewsExcludePreviousNodes.php in Views exclude previous 8
File
src/Plugin/views/filter/ViewsExcludePreviousNodes.php
View source
<?php
namespace Drupal\views_exclude_previous\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\InOperator;
class ViewsExcludePreviousNodes extends InOperator {
public function getValueOptions() {
$this->valueOptions = [
'node_load' => 'Exclude nodes previously loaded (hook_node_load).',
'node_view' => 'Exclude nodes previously viewd (hook_node_view).',
'views' => 'Exclude nodes that where loaded in any node based view.',
];
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['operator']['default'] = 'not in';
$options['value']['default'] = [];
return $options;
}
public function operatorOptions($which = 'title') {
return [
'not in' => t('Is not in'),
];
}
public function query() {
$alias = $this->query
->ensureTable('node');
if (!$alias) {
return;
}
if (!$this->value) {
return;
}
$excludes = [];
foreach ($this->value as $category) {
$excludes += _views_exclude_previous($category);
}
if (!empty($excludes)) {
$this->query
->addWhere($this->options['group'], $alias . '.nid', $excludes, 'NOT IN');
}
}
}