Is there a way to do this without writing a custom view filter plugin?
I'm afraid not.
I am only looking to exclude the first revision.
mymodule/mymodule.module
<?php
/**
* Implements hook_views_data().
*/
function mymodule_views_data() {
$data = [];
$data['node_revision']['exclude_first_node_revision_filter'] = [
'title' => t('Exclude first node revision'),
'help' => t('Excludes the first node revision.'),
'filter' => ['id' => 'exclude_first_node_revision_filter'],
];
return $data;
}
mymodule/src/Plugin/views/filter/ExcludeFirstNodeRevisionFilter.php
<?php
namespace Drupal\mymodule\Plugin\views\filter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views\ViewExecutable;
/**
* @ViewsFilter("exclude_first_node_revision_filter")
*/
class ExcludeFirstNodeRevisionFilter extends FilterPluginBase {
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->valueTitle = t('Exclude first node revision');
$this->definition['options callback'] = [$this, 'generateOptions'];
}
/**
* {@inheritdoc}
*/
public function query() {
$this->ensureMyTable();
// Exclude the first revision of each node.
$this->query->addWhereExpression($this->options['group'], "node_revision.vid <> (SELECT MIN(vid) FROM {node_field_revision} WHERE nid = node_revision.nid)");
}
/**
* {@inheritdoc}
*/
public function adminSummary() {
}
/**
* {@inheritdoc}
*/
protected function operatorForm(&$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function canExpose() {
return FALSE;
}
}