A key problem with core's field-based data structures is that referenced entities are tracked by their primary ID, not by revision. This makes it difficult to build out complex data structures using Entity Reference and referenced entities, and have the parent content managed using the new Content Moderation feature, because once one of the referenced entities is changed the changes will be publicly visible.

Proposals (pick one):

  1. Extend the core Entity Reference module to (optionally) support revisions.
  2. Merge the existing Entity Reference Revisions module into core.
CommentFileSizeAuthor
#71 interdiff_67-71.txt2.33 KBravi.shankar
#71 2812595-71.patch25.25 KBravi.shankar
#67 reroll_diff_55-67.txt14.37 KBravi.shankar
#67 2812595-67.patch25.26 KBravi.shankar
#55 interdiff-53-55.txt1006 byteshchonov
#55 2812595-55.patch27.07 KBhchonov
#53 interdiff-49-53.txt4.8 KBhchonov
#53 2812595-53.patch25.95 KBhchonov
#49 2812595-49.patch22.17 KBhchonov
#46 interdiff-45-46.txt7.09 KBhchonov
#46 2812595-46.patch22.48 KBhchonov
#45 interdiff-44-45.txt5.58 KBhchonov
#45 2812595-45.patch15.39 KBhchonov
#44 interdiff-39-44.txt4.14 KBhchonov
#44 2812595-44.patch11.21 KBhchonov
#39 2812595-39.patch9.79 KBhchonov
#38 interdiff-37-38.txt734 byteshchonov
#38 2812595-38.patch59.65 KBhchonov
#37 interdiff-35-37.txt870 byteshchonov
#37 2812595-37.patch59.59 KBhchonov
#35 interdiff-34-35.txt1.19 KBhchonov
#35 2812595-35.patch59.52 KBhchonov
#34 interdiff-32-34.txt7.29 KBhchonov
#34 2812595-34.patch9.59 KBhchonov
#32 2812595-26-32-interdiff.txt1.65 KBtacituseu
#32 2812595-32.patch10.89 KBtacituseu
#31 2812595-31.patch11.5 KBrgristroph
#26 2812595-26.patch10.04 KBrgristroph
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna created an issue. See original summary.

maximpodorov’s picture

Please use a separate field type for this.

amateescu’s picture

@maximpodorov, why do you think we should use a separate field type?

maximpodorov’s picture

There was the huge discussion in #1837650: Allow referencing a specific revision ID.
The main reason is entity reference and entity revision reference are two separate concepts:
- They require different column count for the field
- The same can be expressed mathematically: they point to different dimension spaces: entity reference is a scalar value, and entity revision reference is a vector which consists of two values, so ordering, equality are not quite clear concepts for them.

Fabianx’s picture

My first reaction was to tend to the idea to fix this issue as:

- Closed (Works as designed)

Reasoning:

What you want when publishing several changes together is 'workspaces' (like in workspace module) or 'site versions' (like in CPS).

However you are right that that would only work correctly with something like field collection, where updating a child entity updates the parent, too.

--

Could you explain how your wanted workflow would look like for an editor?

e.g. Even after publishing the changes to the child entity, nothing happens until the editor has selected the new upgraded version?

I am not yet clear how that would work.

DamienMcKenna’s picture

Ultimately I'd like to have Entity Reference Revisions and a Paragraphs-alike entity system in core.

Fabianx’s picture

#6: That does unfortunately not answer the question.

The question is (from a product perspective):

"How does such a workflow look like? How can we avoid to confuse people?"

e.g.

As a content manager when I want to publish content I need to do three steps:

1. [...]
2. [...]
3. [...]

DamienMcKenna’s picture

The goal is:

As a content editor, I want to 1) create complex pages with different types of things dynamically on the page without having to use a hundred different predefined content types, and 2) be able to use an editorial workflow around it so that drafts of the sub elements behave as if they are parts of the parent entity.

A reference field with multiple referenced entity bundles solves requirement 1, Paragraphs & Entity Reference Revisions solves requirement 2.

Field Collections has a limitation on which types of (field collection) item entities are usable for each (field collection) reference field, so people have worked around this limitation using Javascript and loading a TON of fields onto one field collection item entity (I've worked on sites like that, it's a mess). Like maximpodorov said, we tried in #1837650: Allow referencing a specific revision ID to build the functionality onto Entity Reference, but ultimately the changes were refused (though the included patch has been used on many production sites over the years). Entity Reference Revisions and Paragraphs are a much cleaner solution that otherwise available.

Fabianx’s picture

So there are 2 ways to implement that:

If I change the child, would:

a) the parent be automatically updated with the new revision? (e.g. just by saving the child)
b) the parent be manually updated with the specific revision? (e.g. by an editor)

e.g. Do I understand correctly that you want field_collection like behavior (a), but without all the overhead and problems it brings?

Also:

How would this be displayed with content_moderation? Would only the parent be for moderation in that case with the included things?

Fabianx’s picture

#8: Also what happens in the child lives in several parents?

- Would then all parents be changed at once?
- Would only the parent be changed in which the child was updated? (e.g. track this via IEF somehow)

DamienMcKenna’s picture

Yes, Field Collections and Paragraphs are very similar, only Paragraphs is more stable and more clearly built to allow the child entity bundles (not the objects) to be reused across multiple parent entities, e.g. the same "embedded gallery" Paragraph Type can be used in an Article content type and a Landing Page content type. Field Collection has some limitations and, at this point, isn't worth continuing on D8. But I digress.

  • Child entities would not be reusable nor editable outside of the parent entity's administrative controls. (yes, I know that someone could get into the database, or manually write code to do dumb things, but we wouldn't expose this through the UI, just like we don't let people add fields to fields or other dumb things)
  • The child entity would not be saved until the parent entity was saved, thus editing a child entity but not saving the parent entity would not actually save the child entity.
  • Saving the parent entity would only create a new revision of the child entity if the child entity was edited.
miro_dietiker’s picture

@Fabianx Field Collections is in discussion to be deprecated by Paragraphs:
#2784931: Proposal: Deprecate Field Collections for Drupal 8, focus on Entity Reference Revisions & Paragraphs

Paragraphs builds on top of ERR and relying on its feature "composite relationship". It means, Paragraphs declares that every paragraph is a composite of the host entity. Thus the paragraph entity points to only one single parent, being owned by that.

A paragraph is never edited on its own. Even if the UI could allow that, the paragraph revision will be entangled with the host entity revision. A child should not have own revisions that are forward or moderated separately. Instead, all updates happen in sync.
The child has no own workflow. I guess this can also be compared with the idea if fieldable fields.
#607396: Killer feature: Fieldable Fields in core

Combining the principle with revisions and workflow (forward revisions) and quickedit results in a crazy mess. Many people believe that in future Drupal should only support atomic revisions, but that will make it even worse. Doing 5 small (field) edits with a paragraph containing 5 paragraphs with each 3 fields in 5 languages results in... lots of uncountable updates and bad performance and that's not an extreme example. In reality there will be cases with 50 paragraphs, 20 languages and more.
To make this work acceptable, we need to think about ideas like:
- revision pinning, to create a single forward revision, but only update the same revision as long as it is not published during all quickedits.
- revision cleanup, allowing to drop intermediate revisions if they are excessive and add no value. Revisions can eat lots of unwanted space. We learned in Paragraphs that it's hard/complex to clean up.
- flagged unchangeable revisions, so in case a revision is published, we can consider it atomic.
- major / minor revisions, so users can promote a revision to keep.

Reusability: A regular Paragraph is by design not reusable. This will happen through a separate entity with its own workflow. Promoting one into reusability will allow to add a label and other metadata to maintain the library (extra fields, ...). This part is not yet implemented. A library item could have a tab listing its usages, we could inform the user that some of those point to past revisions and allow the user to update to the most recent one... Or we could allow a user to update all usages when a new revision is published. We could allow the site builder to decide about the workflow and the need of user awareness.
#2414865: [META] Reuse paragraphs / Library

Please ask specifically, if you need to know more about the precise design of Paragraphs or ERR and something is unclear.

Fabianx’s picture

So basically it is field_collection, but with a different technical implementation:

- A host + sub entities that are part of the host

But why would you want to change entity reference fields for that?

I would call that an "embedded entity field", which technically looks like an entity reference field, but internally ensures the embedded entity is always only:

- a) created as part of a host entity (or container)
- b) if edited, the host entity is updated with the new revision
- c) deleted as part of a host entity

Again this is the same as field collection, but without the restriction of only referencing field_collection entities.

It kinda is the best out of both worlds (ER + FC).

However compared to FC, where editing was a nightmare (especially performance wise), it would use the normal IEF or modals or .... Basically only updating the referenced revision in the host after editing. Would still need to ensure to remove the referenced entities from any kind of workflow though.

The main and difficult thing is to ensure that the referenced entities know their container and that the container is unique. (and there is different ways to ensure that obviously).

So for me this feels like a new field type and a different use case from normal ERs (which have re-usability and independence in mind) and I suggest to change the feature request accordingly.

Maybe it is possible to subclass ER to implement the missing parts?

DamienMcKenna’s picture

Paragraphs also isn't limited to one referenced entity bundle per field, which is a key limitation of Field Collection. A key part of the workflow is being able to edit the referenced entities inline, so should we wrap that into this feature request or do it separately?

Fabianx’s picture

#14: Agree and yes the field type should ship with the inlined UI - as per definition the referenced entities should not be edited outside of the context of the parent (as that does not make sense).

If this gets too large a feature request, it might be abetter idea to open an ideas issue with the roadmap and vision?

geek-merlin’s picture

+1 For Entity Reference Revision in core.

This is important for many complex data modeling use cases, not just content moderation.

Fieldable-fields / paragraphs is imho a separate topic, who is interested in this might love #607396: Killer feature: Fieldable Fields in core.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rgristroph’s picture

I'd like to add that I think this is essential. I'm very much in favor of the "Extend the core Entity Reference module to (optionally) support revisions" option. I'm looking now to see if I can make a first-draft type patch in that direction.

tannerg’s picture

I find the use cases outlined by DamienMcKenna to be very common among my customers.

As a content editor, I want to 1) create complex pages with different types of things dynamically on the page without having to use a hundred different predefined content types, and 2) be able to use an editorial workflow around it so that drafts of the sub elements behave as if they are parts of the parent entity.

If Drupal were to better support these use cases out of the box, this would be a game changer for me and my clients.

rgristroph’s picture

I've started on this and you can see some work here:

https://github.com/rgristroph/drupal-2812595/pull/1

It's not ready for a patch yet. I have an error when installing the comments module, I was trying to make my changes apply only if the "reference specific revisions" box was checked, so all existing entity reference fields should continue to work as designed, but I still have something to work on there. This is not yet read for a patch obviously, but hopefully I will post one here soon.

The error is
Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. MySQL needs the 'entity_id' field specification in order to normalize the 'comment__num_new' index in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1509 of /var/www/drupal/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

if that rings a bell for anyone ?

rgristroph’s picture

I fixed the issue I asked about in #21, and updated the repo linked to there.

I moved the checkbox to the field storage settings, and removed a lot of debugging statements that were in there previously.

Now, with that change I can install a fresh drupal (standard profile), create two content types, add an entity reference field on one pointing to the other -- when I save the nodes, and subsequently edit them, the revisions do show up in the node__field table and node_revision__field_ tables, in the "_target_revision_id" columns.

This doesn't do anything related to tracking revisions (like making parent and child go through workflow together) and has no tests, and no way to update or change previously existing fields. The next thing I will work on is the update process.

DamienMcKenna’s picture

@rgristroph: Any reason to build it from scratch rather than "just" adding Entity Reference Revision and improving from there? Does this wheel need to be rebuilt? Again?

DamienMcKenna’s picture

FYI as was mentioned during the multi-year discussion on adding this functionality to the contrib Entity Reference module (#1837650), changing from one to the other can lead to massive data integrity problems.

rgristroph’s picture

@damienmckenna Good points, let get into my thinking a bit and maybe I need to adjust the approach.

I don't want to write much or anything from scratch if I can help it, the changes above are almost all grabbing stuff from entity_reference_revisions and moving it to the entity_reference field in core.

I'm working on a project where it started building complex content with entity_reference a year ago, has accumulated a lot of it, and along the way added a moderation workflow, and then some some hack-ish code to sync workflow states from the top "page display" entity to it's children "page items" entities. It mostly works, the base case is OK but things like reverting a "page display" and getting back the same versions of "page items" don't work.

It would have made a difference to use entity_reference_revisions in all our content types from day one, of course, but it wasn't obvious at that point that we needed to. In the same way new projects starting now will use the core entity_reference also. The common pattern will be people build complex content and enter in a lot of it using entity_reference, as the project matures and gets more users they hit a wall with respect to revisioning their content -- they can't do very standard "drupally" things like revert to previous revisions, and the need to rebuild the content structure using entity_reference_revisions and then do a migration. That feels a bit disconcerting, I think if entity_reference is in core, revisions are in core, and now a content workflow is in core, entity_reference needs to be revision aware and allow these things to work together.

I think it comes down to that Drupal should be keeping all the revisions on the entity reference fields by default, so you don't get into that situation. 99% of the time the revision can be ignored when displaying content, and I think we can make a patch that doesn't change the site-building process for people using the current setup, but makes it so the components of core are all revision-aware if you need them to be.

All the philosophizing aside though, let's get practical --

It will take a while to get any change into core.

We can't set people up to have a data integrity mess, I see the issue with that. I lean towards thinking the current situation is a data integrity mess though, if we can at least reduce the potential for that to a few rare corner-cases that will be a big win.

I also think it will take a long time and a lot of testing to get confidence in any patch here.

rgristroph’s picture

Attaching a patch that encapsulates everything in that repo linked above.

DamienMcKenna’s picture

Status: Active » Needs review

Lets see what the testbot says.

Status: Needs review » Needs work

The last submitted patch, 26: 2812595-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rgristroph’s picture

I'll take a look at those failures and update.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rgristroph’s picture

FileSize
11.5 KB

This patch sets $strictConfigSchema = FALSE on two tests, and I'm not sure that's the right thing to do. Just uploading it to see what d.o does for test results.

tacituseu’s picture

Re #31: that won't work, you need to update core schema YML, and then fix the tests.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hchonov’s picture

Status: Needs work » Needs review
FileSize
9.59 KB
7.29 KB

I've made some adjustments. Please look at the interdiff.

hchonov’s picture

The last submitted patch, 34: 2812595-34.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hchonov’s picture

hchonov’s picture

hchonov’s picture

I've just realized that I have added composer.lock to the patch ... Sorry about that. Here is the clean version.

The last submitted patch, 35: 2812595-35.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 37: 2812595-37.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

The last submitted patch, 38: 2812595-38.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 39: 2812595-39.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hchonov’s picture

Status: Needs work » Needs review
FileSize
11.21 KB
4.14 KB
hchonov’s picture

I think that at first we should not support revision reference fields through the widgets, because that raises a bunch of questions like - what happens with the field value if the referenced entity is saved in a new revision.

We could initially only support setting the field through the API. The field formatters however will be working.

hchonov’s picture

Adding an update to populate the new setting for field storage configs.

Status: Needs review » Needs work

The last submitted patch, 46: 2812595-46.patch, failed testing. View results

maximpodorov’s picture

Please, do this in the Entity Reference Revisions field type. Entity Reference field type is not the right place for such experiments.

hchonov’s picture

Status: Needs work » Needs review
FileSize
22.17 KB

I've worked on older state of 8.7.x, which is why the last patch couldn't apply. Here is a re-roll.

@maximpodorov, the new functionality is available only per setting. You don't get the columns in the DB nor the properties unless you activate the setting in the field storage config. Do you see any problems regarding such approach?

The last submitted patch, 45: 2812595-45.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 49: 2812595-49.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

maximpodorov’s picture

Yes, please see #4 and the whole separate thread ended with "Won't fix".

hchonov’s picture

Status: Needs work » Needs review
FileSize
25.95 KB
4.8 KB

Okay, let me first get it green so that we have it as a reference and see what changes would be required for having one configurable field type. From there we can extract the important parts into a new field type.

hchonov’s picture

Issue tags: +drupalmountaincamp
hchonov’s picture

The last submitted patch, 53: 2812595-53.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 55: 2812595-55.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

hchonov’s picture

In the referenced issue we don't introduce a general revision reference field. With the RevisionReferenceItem from the referenced issue, we can reference only revisions from the entity type on which the field is placed and we don't have the computed property entity yet.
The issue here is about having a general field for referencing entity revisions across different entity types.

We could either extend from RevisionReferenceItem or add additional functionality to it.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

R_H-L’s picture

Any possibility this will see any movement? Really vital feature, but seems to be abandoned.

ravi.shankar’s picture

Status: Needs work » Needs review
FileSize
25.26 KB
14.37 KB

Added reroll of patch #55 on Drupal 9.4.x.

maximpodorov’s picture

This feature exists in the separate module. It's not necessary to get everything in the core (and break BC).

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

maxilein’s picture

Well, it's a nightmare to convert base fields to contrib ...

ravi.shankar’s picture

Fixing failed Drupal CS issues of patch #67.

Status: Needs review » Needs work

The last submitted patch, 71: 2812595-71.patch, failed testing. View results

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Chris Matthews’s picture

From @catch in the #yes-no-queue channel in Drupal Slack re: this functionality in Core:

I have a knee jerk reaction against it. I understand using it for commerce where you want to reference a product frozen in time on an order and similarish accounting stuff, it makes me uneasy for content workflow things for reasons similar to the ones fabianx gives on there. This doesn't mean it shouldn't be supported but I think the issue summary needs better pros and cons.

R_H-L’s picture

Given that entity_reference_revisions is currently the 6th most installed across the current codebase, I'd say the demand is there for the functionality to be in core. It's useful in a few places, such as referencing certain revisions of custom content entities as we do in custom blocks for Layout builder, but I admit ours is a corner case. Paragraphs uses this same model and without being able to reference a revision of a child element, reversion is complicated.