Problem/Motivation
The WSE module extends Diff's RevisionOverviewForm in order to add a "Workspaces" column to the revisions overview page.
See https://git.drupalcode.org/project/wse/-/blob/3.0.x/src/Diff/Form/WseRev...
The ::getRevisionIds() method gets called twice during a build of WseRevisionOverviewForm: once inside parent::buildForm() and then once directly with $this->getRevisionIds().
The problem is that these two queries end up using two different pagers. The result is that the Workspaces column does not paginate correctly.
See #3581936: Workspace column on revisions overview form does not respect pagination.
Steps to reproduce
- Install WSE with Diff and create revisions for some node in various workspaces.
- Either create more than 50 revisions or change the diff.general_settings.revision_pager_limit setting to some small number such that you can page the revisions overview form for the node.
- Note that the Workspaces column does not reflect the pager.
Proposed resolution
While this could be fixed by overriding the method in WSE, I think it makes more sense to make a change in the Diff module itself.
Update Drupal\diff\Form\RevisionOverviewForm::getRevisionIds() such that the result is stored on a class property. That way when we call the same method from WSE we get the cached values instead of having the entity query run again. It's running the query a second time that is causing core's pager manager to get tricked into thinking there are multiple pagers.
Something like:
/**
* Gets a list of node revision IDs for a specific node.
*
* Only returns revisions that are affected by the $node language.
*
* @param \Drupal\node\NodeInterface $node
* The node entity.
*
* @return int[]
* Node revision IDs (in descending order).
*/
protected function getRevisionIds(NodeInterface $node): array {
if (isset($this->revisionIds[$node->id()])) {
return $this->revisionIds[$node->id()];
}
$entityType = $node->getEntityType();
$result = $this->entityTypeManager->getStorage('node')->getQuery()
// Access to the content has already been verified. Disable query-level
// access checking so that revisions for unpublished content still
// appear.
->accessCheck(FALSE)
->allRevisions()
->condition($entityType->getKey('langcode'), $node->language()->getId())
->condition($entityType->getKey('revision_translation_affected'), '1')
->condition($entityType->getKey('id'), $node->id())
->sort($entityType->getKey('revision'), 'DESC')
->pager($this->config->get('general_settings.revision_pager_limit'))
->execute();
$this->revisionIds[$node->id()] = \array_keys($result);
return $this->revisionIds[$node->id()];
}
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork diff-3581969
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
danflanagan8