- Issue created by @asherry
- Status changed to Needs review
8 months ago 8:07pm 9 March 2024 - last update
8 months ago 10 pass - 🇮🇳India Vivek Panicker Kolkata
Seems like a CORE issue.
Trying to fix in https://www.drupal.org/project/drupal/issues/3442267 🐛 Entity Reference Revision not loaded in EntityReferenceFormatterBase Active . - 🇺🇸United States asherry
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, which is well outside the scope of that class and would add complication for extending classes. - 🇮🇳India Vivek Panicker Kolkata
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. - Status changed to Needs work
6 months ago 5:11am 21 May 2024 - 🇩🇪Germany Anybody Porta Westfalica
@asherry could you please provide this as MR and add tests to ensure it works as expected, with and without revisioning enabled?
The current implementation also means that a parent
prepareView()
is never called, if not one of these two if clauses match!So instead of:
+ /** + * {@inheritdoc} + */ + public function prepareView(array $entities_items) { + $field_type = $this->fieldDefinition->getType(); + if ($field_type === 'entity_reference') { + parent::prepareView($entities_items); + } + if ($field_type === 'entity_reference_revisions') { + // See \Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsFormatterBase::prepareView() + foreach ($entities_items as $items) { + foreach ($items as $item) { + if ($item->entity) { + $item->_loaded = TRUE; + } + } + } + } + }
shouldn't it be something like this:
+ /** + * {@inheritdoc} + */ + public function prepareView(array $entities_items) { + $field_type = $this->fieldDefinition->getType(); + if ($field_type === 'entity_reference_revisions') { + // See \Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsFormatterBase::prepareView() + foreach ($entities_items as $items) { + foreach ($items as $item) { + if ($item->entity) { + $item->_loaded = TRUE; + } + } + } + } else { + parent::prepareView($entities_items); + } + }
to be compatible with any parent implementation?
- 🇩🇪Germany Anybody Porta Westfalica
Any plans to finish this @asherry and @Vivek Panicker?