1

I'm building a custom entity document which supports revisions. Revisions are seen as versions of the document (v1.1, v1.2, ...), the title field is revisionable as well. Then there is a custom entity customer, which needs to accept documents. On creation of a customer, I need to point out which revision of the document is suitable for this customer.

I have an entity reference field on the customer to target a document. However, I'm not achieving to target revisions of a document.

I tried entity reference display in views (with a view that supports revisions) but I'm not able to select it in the field settings (no eligible view found). Probably because I can only select 'Document' as target type and not 'Document revisions'.

I tried entity reference revisions module but gave me the same results. This module just keeps track of changes in parent vs child revisions (I guess).

enter image description here

would expect document revisions being available here

I would expect document revisions being available in the settings above!

enter image description here

enter image description here

Any suggestions on how to do this properly, am I missing something? I want to make use of core as much as possible for this one.

Update: I ended up creating a custom field plugin to get the required solution.

6
  • have you tried the Entity Reference Revisions module? Commented Feb 12, 2021 at 8:58
  • Yes, I did but didn't work. I'll update this in my question as well. Commented Feb 12, 2021 at 8:59
  • 1
    By concept this cannot work with core and an entity reference field, as it only allows to store a target_id. You'll need ERR as @M.Anagnostopoulos pointed out, this field type stores a target_id and a target_revision_id
    – Hudri
    Commented Feb 12, 2021 at 9:05
  • Maybe it would be best if we focused on the EER module for the time being while trying to tackle this issue, how exactly did it not work? could you edit your question with details on how you used/configured it. There might be a catch in it which you missed. Commented Feb 12, 2021 at 9:08
  • 1
    I'm not sure ERR works in this context. It was developed for the very close 1:1 relationship of paragraphs with their parent, which keep track of changes parent vs child as the OP has mentioned.
    – 4uk4
    Commented Feb 12, 2021 at 9:10

1 Answer 1

-1

Revisions are stored in a separate db table from content. Views module makes you choose the base table for the query to the database when you're creating a new View (it's commonly called Views type: Content, User, Media, Taxonomy terms).

The easiest way to allow an Entity Reference Field to choose a particular Revision of a Content item is to build the list of Content Revisions items, and not a list of Content items.

Create a new Views entirely but this time choose Content revisions under Show, and not Content (you can't change that from within your existing Content type Views).

Your aim it to have a separate revision in each Views row, because when you're using that list within an ER Field each Views row becomes one checkbox/radio button to select when you're creating a new node.

Revisions can be grouped by their original content ID, Title or something else in common, but I'm not sure if the Entity Reference Views Display type supports that, I expect it doesn't and it won't affect it, you'll still get a plain list of all Revisions and you need to make sure yourself what to output and how to style it to make the options clear. There are probably ways on how to improve the ER Display output in Field widgets but that is out of scope of this question.


I haven't tries this, but usually when listing content referenced through ERs you need to add a Relationship to get any other info than an ID of the referenced entity. You'd need a Relationship to get that info. In your case if you start with Content Views type I expect you'd have to make sure to have each Revision is in a separate row (after you make them appear in results by adding a Relationship, and you'd probably need to list only the Revision info to make them appear in separate rows). I know it's possible to create the reverse ER Views through the forward list Views this way, but haven't tried it with Revisons, maybe the same logic applies.

Anyway, go with the Content Revisions Views type as explained above ;)

2
  • Hi prkos, the view you see in attachment is of type document revision. It lists all revisions correctly. But my ER field doesn't pick up the view (no eligible view found) Commented Feb 13, 2021 at 8:03
  • :facepalm: I'll get back to you after a reboot.
    – prkos
    Commented Feb 13, 2021 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.