Score:1

View of Node revisions exclude first revision of each node

in flag

I have a view of Node revisions. I want to only show revisions that are edits. I want to exclude the first revision of each node.

I think filtering for created <> changed would work, but I could find a filter in views, or a contrib module that does this.

Is there a way to do this without writing a custom view filter plugin?

Kevin avatar
in flag
Couldn't it also be true that the highest revision id is not necessarily the published or current one? Is it possible to query for node revisions whos state is not published?
Binary Alchemist avatar
in flag
I am only looking to exclude the first revision. The publish state, and if it is the current revision or not does not matter to me.
Score:2
ua flag

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;
  }

}
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.