Closed (fixed)
Project:
Entity Reference Revisions
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Jan 2018 at 20:17 UTC
Updated:
24 Jan 2025 at 10:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ashrafabedComment #3
ashrafabedThe attached patch adds support for an ERR label formatter, linked or unlinked.
It shows the label for the appropriate entity revision, and it links to the appropriate revision as well. The matches core's Entity Reference Label Formatter almost exactly.
Notes for a code reviewer:
The differences from core's label formatter are the namespace, most mentions of 'entity reference' are replaced with 'entity reference revisions', and "$uri = $entity->urlInfo();" was changed to "$uri = $entity->urlInfo('revision');" so that the URL points to the appropriate entity revision.
Comment #4
ashrafabedComment #5
ashrafabedComment #6
miro_dietikerHello, thank you for the submission.
Such a new feature needs full test coverage.
Also even such a simple implementation adds maintenance complexity. We need a real world usecase explained where this functionality is used.
The most common use case „Paragraphs“ does not apply here as it doesn‘t have a label.
Comment #7
ashrafabedI've attached a patch which tests the label functionality. It is based off of core's tests for the entity reference field's label formatter.
"We need a real world usecase explained where this functionality is used."
https://debugacademy.com needs this functionality today:
- "Class" entities are created
- They have ERR homework and classwork fields which point to the "assignment" entities
- When a class happens, we reference the homework + classwork + etc using the ERR fields
- On the display side, we display links to the homework + classwork + etc from the ERR fields. we do not want to display the entire homework and classwork contents on the same page.
- The reason we are using ERR fields is because homework and classwork assignments are modified every semester. We want people to be able to look at their "Class" entities, and see links to the appropriate revision of the homework/classwork assignments. This way they are always taken to their semester's homework/classwork revisions, rather than the latest
I expect there are many other use cases for this as well. If the module is to be used outside of paragraphs, having a 'label' formatter seems to be very necessary.
Comment #8
ashrafabedComment #10
ashrafabedTaking another stab at getting the automated tests to pass.
Comment #11
ashrafabedComment #13
ashrafabedLet's see if this will work.
Comment #14
ashrafabedComment #15
ashrafabedCorrection.
Comment #18
ashrafabedMore progress on the tests.
Comment #19
ashrafabedComment #21
ashrafabedGetting much closer.
Comment #22
ashrafabedComment #24
ashrafabedSorry for the patch spam. I believe it's almost ready.
Comment #25
ashrafabedComment #27
ashrafabedI wonder if there's something wrong with the test runner right now. The error messages have increased in number and are now along the lines of:
"Caused by
PDOException: SQLSTATE[HY000] [1049] Unknown database 'jenkins_drupal8_contrib_patches_20547'"
I'll try running the test again later.
Edit: It does seem like these errors are related to the testing environment rather than the tests themselves ( https://www.drupal.org/project/drupal/issues/2906317 )
Comment #28
ashrafabedFingers crossed..
Comment #29
ashrafabedAnother test issue fixed.
Comment #30
ashrafabedComment #31
ashrafabedShould (hopefully) pass now.
Comment #32
ashrafabedComment #33
mpolishchuck commentedI think need improvement here.
In some cases we have entity_reference_revisions field, but we need to show link (and label as well) to the current entity revision.
This patch add this capability. It's based on the patch from comment #31.
So label formatter now have "Ignore referenced revision" setting. If it's set to true - the formatter will show label/link to the current entity revision (instead of actually linked).
Also the patch adds overridden EntityReferenceRevisionsFormatterBase::getEntitiesToView() which can be used to get the same behavior for other for other formatters.
Comment #34
2phaI am just putting this here for anyone who comes here looking for a quick fix to get field formatters for entity_reference_revisions.
I implement the standard entity reference formatters on entity reference revisions with this simple function in a module:
Though, this wont take the revision into account when outputting the field (I don't think).
Maybe this could be implemented into the module and then formatters specific to this module could be implemented which just extend the entity_reference formatters and override which entity is loaded.
Just a thought and I haven't really looked into it.
Comment #35
sinn commentedUpdated patch 31.
Configuration for formatter has been added, fixed Drupal coding standards, renamed deprecated functions. Test has been rewritten - composite entities (like paragraph) don't have own pages, so no need to add routes to them.
Comment #36
sinn commentedFix test for D9.
Comment #37
joevagyok commentedReviewed and tested, moving it to RTBC.
Comment #43
berdirMerged, thanks.
Comment #47
ab.shakir commentedThe ID formatter also has multiple real world use cases although it does not make much sense for Paragraphs. In my case, I have a reference field using the ERR and I want to use the ID in views re-write results while in another scenario I'm trying to embed another view with the help of Views Field View and passing the ID value as a contextual filter.
Comment #48
ab.shakir commented