Problem/Motivation

We need to create a view of revisions, it's not with the base of "node_revision", but similar. In this case the field formatter is a paragraphs field, and the parent entity is a node.

I need the view to show a node revision, and then the paragraph revision that is associated with that node revision. The field formatter display only displays the latest revision, regardless of the parent entity.

Steps to reproduce

Proposed resolution

This looks to be caused by the prepareView method. The class Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase extends class Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase. The prepareView function in that class reloads the entities completely for static caching.

The method in Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsFormatterBase::prepareView, for example, overrides this explicitly to not reload anything.

I suppose there are two ways to address this, one would be to extend the EntityReferenceRevisionsFormatterBase class instead of FieldReferenceFormatterBase directly. Since there are two formatters in this module though, that would involve creating a FieldFormatterBase and then a FieldFormatterBase (for revisions), and then creating two different formatters for both of the two types of fields.

I added a patch that instead just checks for the current field type, and either calls the parent class to reload entities and cache, or, do what the EntityReferenceRevisionsFormatterBase::prepareView does. (the code is just copied over)

Remaining tasks

QA & Tests

CommentFileSizeAuthor
#4 3426834.patch1.02 KBasherry
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

asherry created an issue. See original summary.

asherry’s picture

Issue summary: View changes
asherry’s picture

Issue summary: View changes
asherry’s picture

Status: Active » Needs review
FileSize
1.02 KB
Vivek Panicker’s picture

Seems like a CORE issue.
Trying to fix in https://www.drupal.org/project/drupal/issues/3442267.

asherry’s picture

I'm not sure I agree that it's a core issue, particularly regarding EntityReferenceFormatterBase. This class is very generic. It's meant as a basis for all entity references including entities that are not revisionable as well is config entities.

In order to "load a revision" you would have to actually check if the entity is revisionable, check if the entity is a revision, and then load the revision which is all functionality that is well outside the scope of this class.

Vivek Panicker’s picture

I have done all that you've mentioned.

> It's meant as a basis for all entity references including entities that are not revisionable as well is config entities.
This point I can understand.
Anyways I have raised an MR.
Let's see what the core maintainers have to say about this.