Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Views currently doesn't provide a relationship from the revision table back to the base table by default.
There are though workarounds in both block_content and node module for that.
Proposed resolution
Let's add it.
Remaining tasks
Provide a patch
Review it
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#91 | Drupal 9.4 - Revision User.png | 56.33 KB | dishabhadra |
#91 | Drupal 9.3 - Revision User.png | 77.39 KB | dishabhadra |
#81 | interdiff_79-81.txt | 134.96 KB | mikemiles86 |
#81 | 2652652_81.patch | 17.87 KB | mikemiles86 |
#77 | 2652652_77.patch | 17.08 KB | Ghost of Drupal Past |
Comments
Comment #2
dawehnerThere we go.
Comment #4
jibranThanks for working on this. This is a huge problem for contrib so it's at least major.
Comment #5
dawehnerThere we go.
Comment #6
jibranThis can't be correct.
Comment #8
xjm@alexpott, @effulgentsia, @webchick, and I discussed this and agreed it makes sense for this to be marked major. We all thought it was more of a task though.
Finally, I think this is best targeted against 8.1.x. I think we need an upgrade path?
Comment #9
dawehnerI agree with the 8.1.x part, even it actually already helps contrib and especially custom people to integrate their entities.
Regarding the upgrade path, I disagree. We could of course totally implement an empty update function, but this is about it.
Comment #10
alexpottI think we need an empty update function to clear cache - unless already have an 8.1.x update function in views which there's not... looks like
views_update_8003()
andviews_update_8004()
are going to be the same :)Comment #12
dawehnerAddressed the feedback from alex
Comment #14
dawehnerFixed the failures ...
Comment #15
LendudeMaybe replace $this->entityType->getKey('revision') and $this->entityType->getKey('id') with $revision_field and $base_field, these variables are already set earlier in the method anyway and would make this a little easier to read.
Comment #16
LendudeThis looks more like a help text, and with the 'Get' look a bit weird as a label and could probably be shortened to just 'Content' since everything from the revision is marked 'Content revision'. See screenshots for how this looks now.
No help makes it unclear what the difference between these two thing is:
The label looks weird and way to long:
Manually tested the patch and I got:
Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'langcode' in field list is ambiguous: SELECT node_field_data_node_field_revision.langcode AS node_field_data_node_field_revision_langcode, node_field_revision.vid AS vid, node_field_data_node_field_revision.nid AS node_field_data_node_field_revision_nid, langcode AS langcode FROM {node_field_revision} node_field_revision LEFT JOIN {node_field_data} node_field_data_node_field_revision ON node_field_revision.nid = node_field_data_node_field_revision.nid WHERE (( (node_field_revision.status = :db_condition_placeholder_0) )) LIMIT 11 OFFSET 0; Array ( [:db_condition_placeholder_0] => 1 )
Didn't dig any further yet to find out if this also happens without this patch applied with the original relationships.
Comment #17
dawehner@Lendude
Good point!
Can you please though try to provide a view which reproduces the problem you've described? I tried to get that, but I couldn't
Comment #18
LendudeAttached an export with a failing View. Basic steps to reproduce, multiple languages enabled, View showing node revisions, add relationship to content -> fail. But....this is just as broken without the patch, so no new fails get introduced and maybe we should open a separate issue for this.
But to the patch:
The new label is definitely shorter then it was, but this might be a bit too short :)
The 'add' dialog is still a bit ambiguous (but definitely better then it was). Any way to to make the difference between these two options clearer?
Comment #19
TravisCarden CreditAttribution: TravisCarden at Acquia commented@Lendude: I created #2714717: Content (nid) relationship joins to wrong nodes, which may capture the bug you refer to creating a separate issue for in #18.
Comment #22
benjy CreditAttribution: benjy commentedWe're using this patch against 8.3.x if anyones interested.
Comment #23
johnvI added a simple example of this error here #2446681-18: Error "Column 'langcode' in field list is ambiguous" thrown due to TranslationLanguageRenderer not rendering a field from a relationship. Perhaps in the wrong issue?
[EDIT] Patch #22 does not fix the error.
Comment #25
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedReroll against 8.4.x.
Comment #27
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI have a bunch of views that were affected by The 'content_revision_tracker' table from Content Moderation has been removed. This patch is now essential for displaying any non-revisionable field on a custom entity with the revision table as the base.
I do agree with #18 however, the label is a little confusing in the list.
Comment #28
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI botched the reroll. Fixing.
Comment #29
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedCan I ask what this actually does? Why would we need a relationship from the revision table to the base table based on the revision ID? Does that mean the relationship would fail/not-exist if the given revision wasn't default? Because
vid
in the base table doesn't matchvid
in the revision?If that's the reason we're adding it, we have
@ViewsFilter("latest_revision")
instead and should probably rely on that instead of joining a table to access the same data?Comment #31
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedUploaded wrong patch in #28.
Comment #32
dawehnerThe only thing I was wondering: Should we have some test which actually executes some query? I think we have some test coverage for node module though which should cover that
Comment #34
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI was going to propose removing a chunk of the patch in #29, do you know if that part is still relevant? If there is a use case for it or I'm misunderstanding, happy to put back to RTBC.
Comment #35
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedReroll of #31.
Manually fixed conflicts on:
core/modules/views/src/EntityViewsData.php
core/modules/views/views.install
Comment #36
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedOw, the bot runs
.diff
files as well.. sorry.Comment #37
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedThis part of the reroll I've realized is not correct, since $views_field_name is no longer set previously.
Comment #39
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedThis should hopefully be a correct reroll of #31.
Diff against #35:
Comment #41
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedRe: #29 - I agree this relationship doesn't add much value. Instead, let's add the missing relationship to the
$revision_table
(node_revision
for nodes), so as to give access to the revision_log, revision date, etc.I attach the interdiff that would get this working, please let me know what you think :)
This has been requested here #2674518: Add revision log field to views, and I think it would be very useful for content editors =)
Comment #42
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedIt is also not clear what the difference is between these two in the UI (see #29):
Comment #44
griffincox CreditAttribution: griffincox commentedI'm having a problem that I think is related to this issue. In my standard 'Content' view, I'm trying to add the column "Last Updated By". When I add a User relationship, I should be able to put in a User:Name field that references the User relationship, which ultimately should supply the user that last updated the node... right? Instead, it's supplying the original author of the node, as if it were referencing the Author relationship.
Comment #45
alphawebgroup#39 patch could not be applied to 8.6.x anymore... sorry
Comment #46
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedReroll of #38 (three-way merge did the trick).
Comment #47
alphawebgroupnow it's not compatible with 8.5.x
Comment #49
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedComment #50
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedAs found and fixed in #2977276: Node views integration that joins revisions to the default entity fails to consider langcode, resulting in duplicate rows, we should include the langcode as an "extra" join argument if the entity types are translatable.
Comment #51
jibranNW for #50.
This should be converted into a post-update hook.
Comment #52
Wim Leers@amateescu also helpfully marked #3001146: EntityViewsData does not provide a relationship from the revision data table to a data table as a duplicate! 🙏
Comment #53
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedStraight reroll.
Comment #54
jibran#51 is still pending.
Comment #55
Anas_maw CreditAttribution: Anas_maw as a volunteer commented+1 for #41, adding a relation to the revision table will give us access to date and log message.
Comment #56
PanchoJust a recap. Current patch needs work for:
Comment #58
eddi86 CreditAttribution: eddi86 commentedIt's a little bit confusing... which patch should i use to get a solution for #44 with translated nodes/entities?
I use 8.6.14
Comment #59
eddi86 CreditAttribution: eddi86 commentedAfter testing patch from #46 (applying with problems) i was able to get the revision user name - but only when checked "create new revision" in node edit. The "last updating user" is not stored in the DB without creating a new revision... the uid in "node_revision" table is still the author of the node.
Is this the way to go in Drupal 8, save every change in a new revision? Maybe this should be discused in a new issue.
Comment #61
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRerolling.
Comment #62
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedThanks for the reroll @Sam152
Setting to needs work because although its very close, we still have a bit of work to do, see #56
Comment #64
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRerolling #61 for 9.1.
Comment #65
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #68
minorOffense CreditAttribution: minorOffense at Coldfront Labs Inc. commentedUpdated the patch for Drupal 9.2.x
Looks like they moved one of the test files and two of the test modifications are already part of the new test file.
Comment #69
minorOffense CreditAttribution: minorOffense at Coldfront Labs Inc. commentedPatch appears to apply to 9.3 and 9.4. Figure run the tests and see what it says.I guess not then. That's weird cause it applied locally. Well maybe I'll take a shot at updating it again...Comment #70
Ghost of Drupal PastI added
currently
user_name
is added in Node and Media, this is likely unnecessary after slamming it like this. Not a lot remained of MediaViewsData which I consider a good thing. NodeViewsData also sees a healthy trim.Comment #71
Ghost of Drupal PastComment #72
Ghost of Drupal PastComment #74
Ghost of Drupal PastNow with more langcode. All the previous versions didn't take langcode into account.
Comment #75
Ghost of Drupal PastComment #76
jibranWow, this issue is still open. I reviewed it again. Code changes and test coverage looks good. Only one observation but other than that this is RTBC.
Seems like an unwanted change.
Comment #77
Ghost of Drupal PastRemoved that. No other change.
Comment #78
alexpottI think that rather than have both $entity_id_key and $base_field we should have only one. Changing the existing usages of $base_field to $entity_id_key seems fine to me.
$this->assertNotEmpty() - but also given the following assertions - not sure these are required.
As above.
Same again...
Use hook_post_update_NAME and not a schema numbered update. It's not necessary to use hook_update_N here.
Comment #79
mikemiles86I've made changes @alexpott recommended to the patch from #77.
Comment #81
mikemiles86Updated the patch for 9.4.x and removed the unneeded
AssertNotEmpty()
tests that were in patch #79.Comment #82
Ghost of Drupal PastThis concludes everything Alex asked for and it was RTBC before. Thanks!
Comment #85
alexpottThe code looks great. We need a CR to tell developers about this change and the fact that they can remove code from contrib / custom entity types that provide this relationship because core views will now add it automatically.
Comment #86
jibranCreated https://www.drupal.org/node/3252836
Comment #87
alexpottCommitted and pushed 45347fa580 to 10.0.x and d9bd98f6ed to 9.4.x. Thanks!
Thanks @jibran
Comment #91
dishabhadra CreditAttribution: dishabhadra at Axelerant commentedAs this issue is merged into Drupal 9.4, it fixes the adding the relationship into view automatically for all entities.
But the above patch is not adding filter user_name for node_revision, media_revision and block_content_revision table.
Eg,
Similarly for media_revision and block_content_revision as well.
Before Drupal 9.4 if the content view is using the "Revision User" field was showing the username for the current revision now showing User ID instead of Username and it is breaking the display.
Drupal 9.3 - Revision User Field:
Drupal 9.4 - Revision User Field:
There are related issues with "Revision User" field to show the author name it was added into Drupal core 8.9 onwards and now it got removed again.
https://www.drupal.org/project/drupal/issues/2769289
https://www.drupal.org/project/drupal/issues/3113986
Comment #93
smustgrave CreditAttribution: smustgrave at Mobomo commentedClosed #3086916: Add Views Relationship back to original Term in Taxonomy Term Revision view as a duplicate