Problem/Motivation
You cannot create a view and try to list rendered entities using relationship.
Steps to reproduce (based on Standard profile):
- Add an entity reference field named "field_content" to the "page" content type. Allow content > article references.
- Create and edit a content view.
- Add a relationship for "Content using field_content." or "Content referenced from field_content."
- The row style plugin is "Content" by default.
- Click on "Teaser" in order to change the view mode, nothing happens.
- You can't choose a view mode even if you don't want to actually use a relationship, just having one on your view triggers this.
The problem is a fatal AJAX error triggered when RowPluginBase::buildOptionsForm()
calls RelationshipPluginBase::init()
while providing a wrong argument type (Array
instead of DisplayPluginBase
).
Argument 2 passed to Drupal\views\Plugin\views\relationship\RelationshipPluginBase::init() must be an instance of Drupal\views\Plugin\views\display\DisplayPluginBase, array given, called in /app/web/core/modules/views/src/Plugin/views/row/RowPluginBase.php on line 93
Proposed resolution
Fix it, by passing along the relationship as needed and using it.
Remaining tasks
None.
User interface changes
None
API changes
None
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Instructions |
|
Comment | File | Size | Author |
---|---|---|---|
#318 | 2457999-10.0.x-309.patch | 37.02 KB | joegraduate |
#309 | 2457999-9.5.x-309.patch | 37.03 KB | david.muffley |
#300 | 2457999-300.patch | 38.38 KB | Lendude |
| |||
#300 | interdiff-2457999-298-300.txt | 467 bytes | Lendude |
#298 | 2457999-298.patch | 37.79 KB | Lendude |
Comments
Comment #1
dawehner@lauriii
Are you sure this is not a duplicate of #2451789: Entity reference joins to the wrong base table in views. ?
Comment #2
lauriiiYes. This existed before that other issue existed. I have also tested this with the patch from that other issue and it's still broken.
Comment #3
dawehnerSo, do we talk about header or footer? I seriously, tried to rebuild the view, but I don't see how you are able to select a relationship for header/footer
Feel free to atttach a exported configuration of a view.
Comment #4
lauriiiSo I mean rendered views row. You are able to select the entity be used as relationship but it will still render the entity without relationship
Comment #5
dawehnerI totally forgot that this feature existed. Btw. did you hacked the config directly? I got some failures while doing that.
Comment #7
dawehnerLet's see how much less we have.
Comment #8
olli CreditAttribution: olli commented@param \Drupal\views\ResultRow[] $result?
If the relationship is not required, the $entity might not be available.
same as above
*Renderer::render()
?ResultRow::getEntity($relationship)
?Comment #9
dawehnerThank you for you review!!
Good idea. I still love that syntax.
Good idea!
Comment #10
dawehnerIMHO this is at least major
Comment #11
olli CreditAttribution: olli commentedI was thinking about ResultRow::getEntity() which would make this
if ($entity = $row->getEntity($relationship)) {
but this works too. =)Needs work for the render methods (RendererBase::render(), TranslationLanguageRenderer::render()) that are using
$row->_entity->id()
. I guess the test passes because both entities there have the same id.Do you think TranslationLanguageRenderer::query() and DefaultLanguageRenderer::getLangcode() should also use the relationship? Maybe pass it to constructor?
Comment #12
dawehnerGood point! Do you want to fix that?
You are absolutely right, they both need it as well.
Comment #13
olli CreditAttribution: olli commentedAdded relationship parameter to render and getLangcode methods.
Comment #14
frobI will review this patch this weekend.
Simplytest me came back with an error while applying the patch. Retesting.
Comment #17
frobSo it looks like I will reroll that patch this weekend
Comment #18
lauriiiTutorial how to do a reroll: https://www.drupal.org/patch/reroll
Comment #19
bfr CreditAttribution: bfr at Druid commentedI'll try to reroll it.
Comment #20
Nitesh Sethia CreditAttribution: Nitesh Sethia as a volunteer commentedComment #21
Nitesh Sethia CreditAttribution: Nitesh Sethia as a volunteer commentedComment #22
Nitesh Sethia CreditAttribution: Nitesh Sethia as a volunteer commentedComment #23
bfr CreditAttribution: bfr at Druid commentedRerolled.
Comment #25
bfr CreditAttribution: bfr at Druid commentedNot sure what happened there, seems like there were edits to issue during upload and somehow it attached duplicate?
However, i guess we can ignore the reroll since some other patch was submitted?
Comment #26
Nitesh Sethia CreditAttribution: Nitesh Sethia as a volunteer commentedComment #31
frobIs this still broken? I was unable to reproduce it.
I created two content types
article
page
I added an entity reference field to the page that referenced the article.
I added article content and then I created a page that referenced that article content.
I created a view that adds the article content through the relation and then I set it to render full content and it worked.
So I am not sure what the steps are to reproduce.
Comment #32
dawehnerI could totally imagine that we fixed that problem with some of our field rendering related work ... Does some mind to post a test only patch, to see whether its still broken?
Comment #33
lauriiiComment #35
olli CreditAttribution: olli commentedRemoved RowEntityTest and 'entity' from modules. This fails locally so removing novice tag.
Comment #37
olli CreditAttribution: olli commentedAnother attempt to reroll #13. The interdiff is for #26.
Comment #39
frobI asked back in #31 if anyone was still able to reproduce this bug after some of the other changes that where done. I am still unable to reproduce. I would be able to help if someone said more about what the problem is and if it is still happening on the latest dev.
Comment #40
dawehnerWell, I guess @lauriii should be able to tell us, whether the problem still exists ...
Comment #41
lauriiiSeems to be still problem at least on some level since I'm not even able to configure which display mode should be printed after adding a relationship for the view. Patch attached to this issue fixes that and also makes it possible to print referenced rendered entities
Comment #42
frob@lauriii, Do you have any cm yaml files that we can use to reproduce this? I think tests would also be good for this issue.
Comment #43
CyberschorschI can also confirm that Patch #31 is fixing this issue.
Comment #44
frob@Cyberschorsch, can you confirm that the error happens before you applied the patch.
Comment #45
dawehnerI'm curious whether we should move this function into a trait as \Drupal\views\Plugin\views\field\FieldPluginBase::getEntity is the exact same code
Comment #48
geertvd CreditAttribution: geertvd at XIO commentedSimple reroll for now.
Should that be something like
RelationshipHandlerTrait
? Or should it not be dedicated to Relationships and maybe be added in some existing trait (not finding a decent one).Comment #50
dawehnerGiven that the language renderers cannot be extended this is much less of a BC break
Just curious, is it really valid to extend the list of parameters from an interface?
Comment #51
lokapujyaReroll, and want to see the test only patch.
Comment #53
no_angel CreditAttribution: no_angel as a volunteer commentedComment #55
dawehnerComment #56
xjmAre we renaming this existing test? If so can we not do that in this patch? It makes it difficult to review, which I'm trying to do to figure out how to reproduce this. See https://www.drupal.org/core/scope for more information about scoping core issues.
Comment #57
xjmAlso, exact steps to reproduce through the UI would really help here.
NW for #56 though.
Comment #59
ciss CreditAttribution: ciss as a volunteer commentedSteps to reproduce (based on Standard profile):
The AJAX error is caused by fatal error triggered when
RowPluginBase::buildOptionsForm()
callsRelationshipPluginBase::init()
while providing a wrong argument type (Array instead of DisplayPluginBase).Comment #60
ciss CreditAttribution: ciss as a volunteer commentedFor the record: As far as I can tell this change alone fixed the problem caused by the steps listed in the previous comment.
Comment #61
dawehnerSure, but sometimes its sad when this was really the only reason this blocked the patch. Always remember that fixing bug delivers actually value to users and well, this change was made because it was right. The class we test is called
EntityRow
and notRowEntity
. It is always hard to treat one value against the other.Comment #63
dawehnerThere we go.
Comment #64
alexpottDiscussed with @xjm, @tim.plunkett and @dawehner - we decided that this issue is a major issue which you are able to configure a view through the UI that renders unexpected results.
Comment #65
esolitosI had the same issues as #59, the patch from #63 solved my issue!
Is there a reason why 'none' (an arbirtary string) was chosen over a
NULL
or a constant?Comment #66
dawehner@esolitos
'none' is the default value provided in
\Drupal\views\Plugin\views\HandlerBase::defineOptions
Comment #67
vivianspencer CreditAttribution: vivianspencer commentedI can confirm, the patch from #63 also fixed an issue I was having with relationships in a view.
Comment #68
dawehner@esolitos
Ha, I thought I've totally seen you online before. Cool to meet you last week. Do you think the patch looks alright?
Comment #69
esolitos@dawehner
Since my team switched to Slack I always forget to open irc... It was nice to meet you as well, it's nice to put a face and a voice to the d.o usernames. :)
Back on the topic, the patch looks good and fixes the issue in all tests I did and I'm using it in production on a couple of sites w/o issues.
The only thing I still find weird is that magic 'none' string in the relationship, I'll open an issue to get the magic string into a constant, I believe it makes more sense.
Comment #70
ldavidsp CreditAttribution: ldavidsp at MTech, LLC commentedI did not review the code but the patch in #63 fixes the problem. Do we need tests?
Comment #71
dawehnerA constant is a good idea! Do you mind opening up the followup?
This patch adds a test, but I'm not sure if provides coverage for all changes added by this patch.
Comment #73
dawehnerBack to RTBC, this seemed to be a random failure
Comment #75
jonathanshawAre these fails still random?
Comment #76
dawehnerYes they are
Comment #77
alexpottThis is an API break no? https://3v4l.org/2v5JI
Comment #78
dawehnerWell, we actively haven't made these entity renderers swappable ... so we can change internals.
Comment #79
alexpott@dawehner fair enough - the classes involved here are all hard coded in
\Drupal\views\Entity\Render\EntityTranslationRenderTrait
and\Drupal\views\Plugin\views\field\Field::getEntityFieldRenderer
. It is possible to swap this out at the higher level, sinceDrupal\views\Plugin\views\field\Field
is plugin and you can alter it. But I think it is okay to consider this internal implementation to the plugin.This is a bug fix right? Is this never called ATM? As far as I can this is just broken in HEAD
Comment #80
dawehnerExactly, this is what this issue is all about.
Comment #81
ayalon CreditAttribution: ayalon commentedDisplaySuite Plugin is breaking if you apply the patch.
Comment #82
dawehner@ayalon
Can you explain a bit more how its breaking?
Comment #83
ayalon CreditAttribution: ayalon commentedAs soon as I open a page based on Display Suite I get this error after applying the patch:
Fatal error: Declaration of Drupal\ds\Plugin\views\Entity\Render\TranslationLanguageRenderer::getLangcode(Drupal\views\ResultRow $row) must be compatible with Drupal\views\Entity\Render\EntityTranslationRendererBase::getLangcode(Drupal\views\ResultRow $row, $relationship = 'none')
Comment #84
ayalon CreditAttribution: ayalon at Liip commentedThe attached patch is needed to make #63 patch compatible with Display Suite.
Comment #87
LendudeIt seems DS does exactly what is being described in #77-#79, so would this be considered an API/BC break after all with examples available in contrib?
Retested the patch in #63 and its still good, so if this is still not considered an API change this can go back to RTBC I'd say.
Comment #88
ayalon CreditAttribution: ayalon commentedBut still, every page that is using Display Suite will have a white screen of death if the patch I posted is not used.
Comment #89
james.williams CreditAttribution: james.williams at ComputerMinds commentedComment 84 adds a patch for Display suite, not core. Please open a new issue with that patch, for Display Suite. This core ticket is RTBC, as of comment 76, so I'm setting it back to that.
Comment #90
dawehner#84 could be added to DS before this patch landing. That sounds like an okay way.
To be honest these entity renders where meant to be purely internal.
Comment #91
jonathanshawI created a critical DS issue: #2806729: Entity field renderers are adding relationships.
Comment #92
alexpottThis is pain and potentially could break BC for more than just display suite. I think we should consider a fix that does not break contrib. Maybe we could make the method not abstract and provide a default implementation. That way we can avoid the hard break. Putting back to needs review to get sub-system maintainer opinions.
Comment #93
alexpottI.e do the attached patch...
Comment #94
dawehnerI'd be honestly totally happy about this particular change. In general I really like that we haven't made these renderes another plugin type as it saved us from overgenerialization.
Comment #95
alexpott@ayalon any chance you can confirm that the new approach taken allows display suite to continue to work?
Comment #96
catchassociated - can be fixed on commit.
Otherwise looks great but yeah let's get confirmation that display suite is happy.
Comment #97
ayalon CreditAttribution: ayalon at Liip commented@alexpott:
Thanks for the non breaking patch. I removed my display suite patch and reverted Display Suite to 8.2.6 version. Then I applied your latest patch. Generallyit works but there are strict warnings on every page:
Strict warning: Declaration of Drupal\ds\Plugin\views\Entity\Render\RendererBase::preRender() should be compatible with Drupal\views\Entity\Render\EntityTranslationRendererBase::preRender(array $result, $relationship = 'none') in Composer\Autoload\includeFile() (line 412 of htdocs\xx\vendor\composer\ClassLoader.php).
Strict warning: Declaration of Drupal\ds\Plugin\views\Entity\Render\TranslationLanguageRenderer::getLangcode() should be compatible with Drupal\ds\Plugin\views\Entity\Render\DefaultLanguageRenderer::getLangcode(Drupal\views\ResultRow $row, $relationship = NULL) in include() (line 11 of modules\contrib\ds\src\Plugin\views\Entity\Render\TranslationLanguageRenderer.php).
So this means that additional patching of Display Suite is necessary anyway.
Comment #98
jonathanshawSo is this ds's problem to fix the warning, or does this imply something needs to be changed here?
Comment #99
ayalon CreditAttribution: ayalon commentedThe issue has to be fixed here. The notice is coming from the latest patch of @alexpott. With php strict you cannot do what has been done.
Comment #100
dawehnerWell, there is no way to fix that properly without changing the signature IMHO. Here is a suggestion, let's fix this bug just in 8.3.x
Comment #101
kclarkson CreditAttribution: kclarkson commentedSo has a decision been made here about the patch and display suite?
Does anyone know if there are other modules out there besides display suite that create view content displays in views that this patch could impact?
It would be great to hear back from the maintainers from Display Suite and get this one patched As soon as possible because its a critical issue.
At this point am I supposed to just apply the patches separately?
thank
Comment #102
realityloop@ayalon I'm not seeing any strict warnings with Display Suite 8.2.6 (unpatched) with Drupal core 8.2.4 using the following patches:
Comment #103
alexpott@realityloop if I get ds 8.x-2.x and apply the patch to core 8.2.x and then run the
Drupal\ds\Tests\BlockFieldPluginTest
test I see the warnings that @ayalon is reporting. Not sure what to do here.Comment #104
kekkisMy two cents: go ahead and "break" the API, the result is a warning "only" after all. This will let contrib developers fix their code quite conveniently. Essentially what @dawehner is saying in #100.
Note that at least Search API will also be affected by this change. I'm about to add an issue there much alike the one in DS.
Comment #105
dawehner@alexpott
So what happens if we fix this just in the next minor release, but keep the current patch release as it is. Would that be a safe change?
Comment #107
rcodina CreditAttribution: rcodina commentedWhen this will be fixed on 8.3.x? I'm using the 8.3.0-beta1 and I'm experiencing the related issue #2806015: Recoverable fatal error: Argument 2 passed to Drupal\\views\\Plugin\\views\\relationship\\RelationshipPluginBase::init() must be an instance of Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase
Comment #108
jibranI think it is worth breaking the BC for next minor release. We can create an announcement for the change.
Comment #109
LendudeThe full BC version (with thanks to @Xano for helping me wrap my head around this). Adds methods for the 'with relationship' versions and leaves the original methods intact.
Ran this against
\Drupal\ds\Tests\ViewsTest
and it ran without exceptions.The #93 is an array() => [] reroll, the interdiff is against the reroll (the interdiff is hard to read I thought).
This probably needs work for at least some docblocks that need updates (and maybe some @depricated in some places), but the question is, is this preferable to a BC break?
Comment #110
LendudeAnd now with the actual patch.....
Comment #113
LendudeThis should clear up some fails.
Comment #114
lokapujyaIs it really possible that entities could have same id?
Comment #115
james.williams CreditAttribution: james.williams at ComputerMinds commented@lokapujya they are different entity types, so I would have thought that is quite possible, yes?
Comment #116
lokapujyaYeah, I didn't notice that they were different entity types.
Comment #117
lokapujyaThis patch fixes another problem, not sure if everyone is aware of it:
Without this patch,I created a view. Added a relationship. Then, clicked on Format->Show: Content. That brings up the "Page: How should each row in this view be styled" screen. Then, when I click "settings", nothing happens.
After this patch, the "Page: Row style options" screen will show up after clicking "settings".
Comment #118
dawehnerI like that.
Comment #119
LendudeDiscussed this direction with @dawehner at DevDays.
Made the 'byRelationship' methods so that the relationship is non-optional and made the original methods use the 'byRelationship' methods to reduce code duplication.
Comment #120
ayalon CreditAttribution: ayalon commentedGreat progress! Thanks lendude for your work. #119 works for me.
Comment #121
dawehnerOnce its none and once NULL, this is confusing
Comment #122
Lendude@dawehner would something like this be better? They are actually 2 different things. Most of EntityRow is referring to the relationship handler, but query is referring to the relationship table or alias. Hence the different defaults.
This would make the variable name in the calling function different then that used in the called function, which is not great either, but updating query() seems a little out of scope :)
Comment #123
jibranHow about this?
Comment #124
dawehner+1 for
$relationship_table
and the simplification introduced by @jibranComment #125
tstoecklerAs far as I can tell, this is overridden by every single child class, so I'm not sure what the value of this is.
I only stumbled on this because of the
getUntranslated()
call which seems very suspect to me as there is no comment there to justify it and as far as I can tell no test for this particular line either.So I think we can either just drop this function altogether or I would prefer some justification (i.e. code comment and/or test) for this.
Comment #126
lokapujyaWhat does the relationship have to do with language? Yes, entity has to be rendered in a particular language, but what does the relationship have to do with selecting the language?
Comment #127
mikeker CreditAttribution: mikeker as a volunteer commentedMoved the steps to repro (from @ciss in #59) into the issue summary.
Comment #128
mikeker CreditAttribution: mikeker as a volunteer commentedComment #129
jojonaloha CreditAttribution: jojonaloha commentedWe have been using the patch in #93. After a security update we tried using the new patch in #123, but it causes fatal errors with Views Parity Row
The patch in #93 does not cause this problem. It seems that this might be an API change and the
method either needs to be added to
Drupal\views\Entity\Render\RenderBase
orDrupal\views\Entity\Render\EntityTranslationRendererBase
. Maybe even add a check inDrupal\views\Plugin\views\row\EntityRow::preRender()
to check that function exists or that it is a subclass of the correct super class; which would mean that Views Parity Row would need to be updated.Comment #130
LauraRocksIs it okay to ask what is going on with this issue? It seems to me that the main problem is gone, or at least I could get the view to work properly but as stated here in#41 and #117, when you have a relationship for entity reference in place, you can't change the view mode that you want your content to appear, it gives an Ajax error. If you get it right the first time, no problem, but if you want to change it, you have to remove the relationship, change the view mode and put the relationship back. So it's not a major flaw, but pretty annoying...
Comment #132
Lendude@tstoeckler how about this? just provide the minimum we need to? make getLangcodeByRelationship() default to getLangcode()
We can't take the method out, because that would break things when modules extend EntityTranslationRendererBase but not implement the method, right?
@jojonaloha Views Parity Row \Drupal\views_parity_row\Plugin\views\Entity\Render\TranslationLanguageRenderer should extend \Drupal\views\Entity\Render\TranslationLanguageRenderer and maybe not Drupal\views\Entity\Render\RendererBase like it currently does. That should clean things up. But don't know the reason behind that setup, so that might not work.
Comment #133
lokapujyaShould it be declared abstract?
Comment #134
LauraRocksLooked at this in DrupalCon Vienna with @Lauriii and this issue needs an updated issue summary. In comment #41 there is a explanation about what is still left from the original issue.
Comment #135
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #136
Anonymous (not verified) CreditAttribution: Anonymous commentedUpdated issue summary to be a bit better. Let's not let minor stuff like that hold up fixing a major issue for site builders.
The patch works for me as well. Unless there are other major concerns with #132 it looks like a good patch.
Comment #138
dagmarRe-rolled. #132 didn't apply anymore.
Comment #139
Anonymous (not verified) CreditAttribution: Anonymous commentedCool, that one passes.
Comment #140
xjmLooks like #133 hasn't been answered yet; also maybe another review from @tstoeckler could be helpful? Thanks!
Comment #141
tstoecklerAs far as I can tell, these can now be removed, as they are the same as the parent implementation.
This would also alleviate #133.
(If not, I have a question: Why does
TranslationLanguageRenderer
have a default value for the$relationship
parameter, while the others do not?)Comment #142
BerdirSetting to needs work for that, will try to do a reroll.
Just run into this myself. It's worth pointing out that this results in a fatal error and prevents you from chosing a view mode even if you don't want to actually use a relationship, just having one on your view triggers this.
Comment #144
AnybodyConfirming the problem still exists.
Comment #145
jonathanshawAddresses #141 which is supposed to fix #133. If the tests are green and interdiff show good implementation of #141, then someone can set to RTBC per #124 and #136.
Comment #146
jonathanshawComment #147
jonathanshawComment #148
dawehnerNice simplification!
Comment #149
AnybodyPerfect, confirming RTBC. Can we get this into the next stable release?
Comment #150
tstoecklerPatch looks really great now, thanks for all the effort!
Sorry, but found one more thing:
This can be removed now, I think, as it's identical to the parent implementation.
Comment #151
jonathanshawFixed #150
Comment #153
jonathanshawSorry, hit limit of my git patch fu. Can't wait for the developer tooling initiative for drupal.org ...
Comment #154
jonathanshawEncoding weirdness. Interdiff same as #150.
Comment #155
dawehner@tstoeckler
Nice find!
Comment #156
tstoecklerThanks for the quick fix! RTBC++
Comment #158
LendudeSilly bot, saying it failed when it didn't
Comment #160
jonathanshawComment #161
landsman CreditAttribution: landsman commentedPatch 2457999-153.patch working for me, thank you @jonathanshaw !
Drupal version: 8.4.3
PHP 7.1.8
Comment #162
joumCan confirm that #154 works brilliantly.
Comment #163
dddbbb CreditAttribution: dddbbb as a volunteer commentedPatch in #154 working well for me, many thanks.
Drupal 8.4.5
PHP 7.1.11
Comment #164
alexpottMaybe this is old code from an alternative fix but I don't understand why we're adding this method as getLancode() is public too. And none of the calls are from another class so even if it was protected that wouldn't matter. Ah yeah this is because we started removing stuff after #141.
Is there anything more we can trim here?
Comment #165
alexpottAlso we need a change record here for the changes to \Drupal\views\Entity\Render\EntityTranslationRendererBase. It'd be great though if we could somehow come up with a way of fixing that was less disruptive.
Comment #166
AnybodyI can confirm the patch works perfectly with Drupal Core 8.5
Comment #167
Serris CreditAttribution: Serris commentedpatch worked for me in 8.5.1 as well
Comment #168
danthornePatch also worked for me on 8.5.1
Comment #169
LendudeCR added https://www.drupal.org/node/2959032
Went through this again, and I can't find anything more we can trim.
Agreed, but I think we went through quite a number of options here and this was the only way we found not to break major contrib modules.
Comment #170
dawehnerI gave it another review. +1 for all of it
Comment #172
AnybodyResetting to RTBC. This seems to be a testbot mistake...
How can we ensure this important fix will be part of 8.6?
Comment #174
tacituseu CreditAttribution: tacituseu commentedFailed because of broken HEAD: #2960013: i18n menu links translation in wrong directory.
Comment #175
zanvidmar CreditAttribution: zanvidmar as a volunteer commentedPatch #164 worked for me in 8.5.3. Tnx!
Comment #176
AnybodyConfirming RTBC again. We're using this in production since month. How can we get this into the next 8.5.x release and 8.6.x?
Comment #178
tacituseu CreditAttribution: tacituseu commentedUnrelated failure.
Comment #179
AaronBaumanRTBC++
Please commit!
Comment #180
nevergone CreditAttribution: nevergone commentedComment #181
nevergone CreditAttribution: nevergone commented#164 rerolled with 8.6.x.
Comment #183
markpavlitski CreditAttribution: markpavlitski commentedRerolled against latest 8.6.x HEAD.
Comment #184
jonathanshawComment #185
AnybodyComment #186
AnybodyConfirming RTBC for #183. Works perfectly on 8.6.x and 8.7.x
Comment #187
dagmarI'm not sure about some side effects of this:
If there is a relationship defined in the parameter, but is not defined in the $row, it returns NULL.
Then. This value is used by
renderByRelationship
. That says it always returns an array. Which is not true based on the code of the method.So either:
render()
was doing.Comment #189
BerdirJust a reroll for 8.7.x for now.
Comment #190
swilmes CreditAttribution: swilmes commentedJust to add, I was able to apply the 8.6 patch in #183 but afterwards I can't open the "Query Settings" modal. Error is " Invalid arguments passed in /var/www/docroot/core/modules/views/src/Plugin/views/query/Sql.php on line 320".
Edit: The error I'm getting is because $this->options['query_tags'] = NULL and obviously the implode command won't work. I can fix it with a check on the value first, but I'm not sure what in the patch would be changing this. I may have a separate issue altogether. I am using contextual filters or as well, so it could be something there.
Comment #191
jordan.jamous CreditAttribution: jordan.jamous at Eighty Options commented#189 worked for 8.7.x. Thank you.
Comment #192
jonathanshawNW for #187
Comment #193
Anonymous (not verified) CreditAttribution: Anonymous commentedOur site breaks horribly in 8.7 without the patch in #189. How'd this make it through?
The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\views\Entity\Render\TranslationLanguageRenderer::preRenderByRelationship() in Drupal\views\Plugin\views\row\EntityRow->preRender() (line 251 of core/modules/views/src/Plugin/views/row/EntityRow.php).
This is when visiting a page with a view that has referenced nodes displayed.
Comment #194
LendudeRe: #190
I can open the query settings without problem on a vanilla umami install. If this is really related to the patch we need some steps to reproduce that.
Re: #193
Make it through what? TranslationLanguageRenderer::preRenderByRelationship() doesn't exist without this patch, nor are there be any calls to it without this patch. Seems more likely it was using this patch pre-8.7 also.
This addresses #187
Comment #195
dagmarI reviewed this patch again and indeed achieves my concerns of #187.
Comment #196
AnybodyConfirming RTBC! Thank you all, nice to have this fixed in core soon.
Comment #197
Anonymous (not verified) CreditAttribution: Anonymous commentedYou're right, pre-8.7 we were using this patch :)
8.7 broke the patch, looks fixed now.
Comment #198
grantkruger#194 worked for me for 8.7.1. My thanks to Lendude and others who keep rerolling this patch all these years. As a stand-alone part time Drupal site maintainer your efforts are incredibly helpful to me.
Comment #200
dagmarBack to RBTC. Random test failure #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest
Comment #202
jonathanshawRandom fail: #3029999: CKEditorIntegrationTest fails randomly
Comment #203
badrange CreditAttribution: badrange at Digia commentedThis has been RTBC for 2 months. What is it that holds it back from being committed?
Comment #204
xjm@badrange, many committers are partly or entirely volunteers, and all are humans who sometimes take vacations. :) Three committers are on vacation this month.
All issues marked RTBC will be addressed at some point (whether with a commit or a further comment asking for further discussion/changes).
Comment #205
badrange CreditAttribution: badrange at Digia commentedThanks for getting back to me xjm! I asked because I have some spare time just this week and wanted to know if there was anything I could do to push this further, like adding some issue tags to ensure that the right person spots it at the right time or similar.
I wish every single core committer a long and lovely vacation!
Comment #206
plachManually/tested and reviewed #194 and it works great, thanks to everyone working here for the thorough reviews and testing!
I agree with @alexpott that ideally we would not introduce changes in signatures of public method not marked as
@internal
, however all the renderer code is pretty self contained and hard to exploit outside its very limited (and hard-coded) use case, so I believe it's unlikely that we have any codebase out there extending any of the affected classes (or using the trait directly). Changes are preserving BC for callers, so I think it should be safe enough to commit this. I think a way to mitigate Alex's concerns could be to commit this only to 8.8.x initially and check whether any breakage is reported. We can leave the issue RTBC for 8.7.x and backport it once/if it's deemed safe enough.Comment #207
plachOn a second thought, would it be feasible to add a
::getEntityTranslationByRelationship()
method and leave this signature untouched?Comment #208
devkinetic CreditAttribution: devkinetic commented@plach +1 on that solution.
Comment #209
plachComment #210
Patrick Ryan CreditAttribution: Patrick Ryan commented+1 so far so good on both #194 and #207
Comment #211
baisongRunning into this issue too, on 8.7.7, and both #189 and #194 fail to apply
Comment #212
Jon Pollard CreditAttribution: Jon Pollard commentedAlso 8.7.8, patch won't apply
Comment #213
PFEnriquez CreditAttribution: PFEnriquez commentedIn the meantime you can use the solution posted on #79
It is only a temporary solution until someone reroll the patch.
Comment #214
sathish.redcrackle CreditAttribution: sathish.redcrackle at Red Crackle commentedI tested the patch with 8.7.7, 8.7.8 versions and i dint found any errors.
Comment #216
LendudeThis addresses #207.
Comment #217
jibranDo we need some kind of @todo to make sure this method gets removed and not be used anymore?
Comment #218
Lendude@jibran yeah, maybe. But in an ideal world, we would:
And since we can't deprecate stuff in D8 anymore, it's really D(x + 1).....
Or we can just leave them both in.... ¯\_(ツ)_/¯
Comment #219
jibranYeah, I'd rather commit #194 instead. It has the correct BC, imo but anyway #207 is addressed so back to RTBC.
Comment #220
plachI was hoping to commit this, unfortunately more review/testing revealed that the latest patch does not take multilingual + relationships into account in one specific case:
I realized that the
$relationship
parameter is not actually used in the method body. We need also anEntityTranslationRendererBase::getLangcodeByParameter()
method so that the new::getEntity()
method can be invoked inDefaultLanguageRenderer::getLangcode()
with the proper$relationship
info. If we don't do so, when dealing with a relationship, the default language of the base entity instead of the referred entity will be returned, which would lead to unexpected results as soon as the two entities have different default languages. I'm attaching a DB dump of the local test site I used to confirm this. The view there can be used to add test coverage for this.EntityTranslationRendererBase::getLangcode()
andEntityTranslationRendererBase::getEntityTranslation()
should become thin wrappers around the new correspondingEntityTranslationRendererBase::getLangcodeByRelationship()
andEntityTranslationRendererBase::getEntityTranslationByRelationship()
methods and would hardcode the'none'
relationship, as, for instance,EntityTranslationRendererBase::preRender()
is doing.Unfortunately
EntityTranslationRendererBase::getLangcode()
is currently an abstract method, which means thatEntityTranslationRendererBase::getLangcodeByRelationship()
needs to be abstract as well. However this should be akin to adding new methods to interfaces and thus allowed by our BC policy, I'll check with a release manager.We will need to update all invocations of
EntityTranslationRendererBase::getLangcode()
andEntityTranslationRendererBase::getEntityTranslation()
to use the new methods instead.Comment #221
plachI just confirmed with @catch that the approach I suggested is acceptable from a RM perspective, if the logic is correct.
Comment #222
LendudeJust a reroll for #3087692: Remove the core key from views configuration. for now, looking into the rest. 'Needs review' to run the testbot, but still needs work.
Comment #223
Lendude@plach going back down the rabbit hole here.....doing #220 would essentially move us back to the patch in #123. Except there we added
getLangcodeByRelationship
as a non-abstract method to provide BC. But then we stripped everything off again to make this more lean.The reason we went through all the trouble of not having a BC breaking patch (even if it was strictly allowed by the guidelines) is that we have known BC breaks in both Display Suite and Search API, two pretty major modules (30k and 50k D8 installs). So I'd really be in favour of not breaking BC here.
Ok, so this adds getLangcodeByRelationship back in, but now correctly, since I now see what happend in #125 (better late then never I guess), but in a BC respecting way, so a silly stub method on
EntityTranslationRendererBase
to make sure nothing breaks.This fixes the fail in #220, but trying to wrap my head around how to get a test in the proper state to test this.
Comment #225
plach@Lendude:
The patch looks very good now, thanks!
However, there are a few more invocations of
EntityTranslationRenderTrait::getEntityTranslation()
that need to be updated to use::getEntityTranslationByRelationship()
, e.g.\Drupal\views\Plugin\views\field\RenderedEntity
.You should find the test view I used to manually test this in the DB dump at #220, along with some test content and the required configuration. Converting that into a test should be enough. Alternatively
RowEntityRenderersTest
could be a good starting point.Comment #226
steveoriolFail to apply the patch #223 or #222 on D8.7.8 ou D8.7.9 via composer.json
but patch from #216 : 2457999-215.patch works...
Comment #227
rcodina CreditAttribution: rcodina commentedPatch #223 applies correctly on 8.8.1 via composer.
Comment #228
Ludo.RSame here: Patch #223 applies correctly on 8.8.1 via composer and works fine, thanks!
Comment #229
xjmComment #230
brandonratz CreditAttribution: brandonratz as a volunteer commentedPatch #223 applies clean on 8.8.5. Fixes a AJAX error on the view mode selection when a relationship is present.
Comment #232
narendra.rajwar27Comment #233
narendra.rajwar27patch applied in drupal 9.1.x-dev version to make relationship for rendered entity on Views working.
Comment #234
jonathanshawThanks!
Comment #235
jonathanshawNW for #225
Comment #236
BerdirJust a reroll for 8.9.x for those who need it.
Comment #237
i-trokhanenkoThe #236 patch works well for me, thanks @Berdir
+1 RTBC
Comment #238
sharma.amitt16 CreditAttribution: sharma.amitt16 as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedI can confirm that issue persists in D9.1.x branch also. I tested this as per steps to reproduce given in IS. After clicking on the teaser nothing happens.
But the patch #236 is not applying on D9.1.x getting error
But patch applied successfully with 8.9.x branch as given in previous comments as well. Also, it fixed the problem in 8.9. It works fine.
Comment #239
BerdirYes, as I wrote, #236 is specifically a reroll for 8.9, the previous patch is for 9.1 Needs work is correct though for tests.
Comment #240
sharma.amitt16 CreditAttribution: sharma.amitt16 as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedOh, I missed that. Apologies, checking patch #233.
Removing the reroll tag and changing the status.
Comment #241
sharma.amitt16 CreditAttribution: sharma.amitt16 as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedTested #233. Working fine with 9.1.x as well.
+1 for RTBC
Comment #242
AnybodySetting this back to Needs work as of #239 (tests) and #225 (more invocations of EntityTranslationRenderTrait::getEntityTranslation()) while I can confirm that the patches work perfectly for me in our projects.
Thanks a lot!
Comment #243
lzimmerman_jr CreditAttribution: lzimmerman_jr commented#223 is failing for 8.8.8 today; I think we'll need a reroll for this version.
Comment #244
lzimmerman_jr CreditAttribution: lzimmerman_jr commentedTesting an updated patch for 8.8.x based on #223, I believe the only change causing failure was an array change for coding standards, from 8.8.7.
(File core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php)
This slight update applies cleanly for me.
Comment #245
bkosborneThe patch in #236 worked fine for me on 8.8.8
Comment #246
lzimmerman_jr CreditAttribution: lzimmerman_jr commentedRetested and that one works for me also on 8.8.8!
Comment #247
Peacog CreditAttribution: Peacog as a volunteer commentedRe-roll needed for 9.1.x due to some changes in core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php
Comment #249
Peacog CreditAttribution: Peacog as a volunteer commentedA better re-roll...
Comment #250
chucksimply CreditAttribution: chucksimply commented#236 works for me on 8.9.1
Comment #251
eblue CreditAttribution: eblue at Northern Commerce commented#236 works for me on 8.9.1 as well.
Comment #252
othermachines CreditAttribution: othermachines commented#236 resolves the issue for me on 8.9.1. Thanks!
Comment #253
en-cc-org CreditAttribution: en-cc-org commented#236 was working for us on 8.9.1 but patch fails to apply when updating to 8.9.6
We use https://github.com/cweagans/composer-patches and all other (module) patches re-applied as expected. Just checking to see if others are experiencing.
Installing drupal/core (8.9.6): Downloading (100%)
Extracting archive - Applying patches for drupal/core
https://www.drupal.org/files/issues/2020-05-30/cannot-use-relationship-2... (Issue #2457999: Cannot use relationship for rendered entity on Views)
patch '-p1' --no-backup-if-mismatch -d 'web/core' < '/tmp/5f6a6b79951a3.patch'
sh: patch: command not found
patch '-p0' --no-backup-if-mismatch -d 'web/core' < '/tmp/5f6a6b79951a3.patch'
sh: patch: command not found
patch '-p2' --no-backup-if-mismatch -d 'web/core' < '/tmp/5f6a6b79951a3.patch'
sh: patch: command not found
patch '-p4' --no-backup-if-mismatch -d 'web/core' < '/tmp/5f6a6b79951a3.patch'
sh: patch: command not found
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-05-30/cannot-use-relationship-2...
Comment #254
othermachines CreditAttribution: othermachines commentedHi @en-cc-org - We updated to 8.9.6 with no issues with this patch. We are also using cweagans/composer-patches. The patch itself is the same. The "command not found" output tells me you have some other issue.
Comment #255
en-cc-org CreditAttribution: en-cc-org commentedThank you - after many more hours, think the issue is Pantheon's Terminus Composer plugin: https://github.com/pantheon-systems/terminus-composer-plugin/issues/7 reported by another user in May.
Comment #257
Dippers CreditAttribution: Dippers commentedThe patch in #236 appears to break the 'Alternating View Mode' feature of the 'Display suite: content' row plugin. It causes that plugin to ignore the specified view modes and just use the default view mode.
The problem is that DS extends EntityRow and EntityTranslationRenderedBase to implement it's own renderer. This overrides EntityTranslationRenderedBase>preRender() to execute its renderer but it does not override EntityRow->preRender(). This means the original EntityRow->preRender() is run which now calls EntityTranslationRenderedBase->preRenderByRelationship() and since this does not exist in the extended DS class the DS renderer is bypassed.
The fix would seem to be to extend EntityTranslationRenderedBase->preRender() rather than introduce the new methods.
Comment #258
phjou#249 seems to be working. 236 is not applying anymore on D9
Comment #259
BerdirReroll for 9.1.x.
Comment #260
phjou@Berdir: Thanks for the reroll, works good
Comment #261
AnybodyI can confirm #236 to be working perfectly for Drupal 8.9 without any problems for month and reroll #259 for Drupal 9.1. Issue raised in #257 by @Dippers should be created as follow-up issue in DS, I guess? Would you like to do this already @Dippers?
So RTBC is +1, but tests are still missing as of @Berdir's comment in #239 (tests) as @Berdir commented #259 to be "just" a reroll. So setting this back to needs work for Tests.
Comment #262
nattyweb CreditAttribution: nattyweb commented#236 resolved the problem for me with D8.9.13. Many thanks - only just come across this problem.
Comment #263
ArtusamakI confirm that #259 fixes the issue on 9.1.x (9.1.3 in my situation).
Thank you for the patch.
Comment #264
ccjjmartin CreditAttribution: ccjjmartin as a volunteer and at Four Kitchens commentedConfirmed functional on #259. Running Drupal 9.1.3.
Comment #266
super_romeo CreditAttribution: super_romeo commentedI confirm that #259 fixes the issue on 9.1.x (9.1.8 in my situation).
Comment #267
donquixote CreditAttribution: donquixote commentedReroll for different Drupal versions, for people who need it.
I personally need 8.9.x.
For 8.9.x I had to resolve a conflict in core/modules/views/tests/src/Kernel/Plugin/RowEntityTest.php. I applied PhpStorm automatic resolution, hope it's ok.
EDIT: I marked each file with a Drupal version for testing on upload. But nothing is happening :(
Comment #268
Ron Collins CreditAttribution: Ron Collins commentedThe patch for 9.2 in comment #267 worked for me.
Comment #269
rcodina CreditAttribution: rcodina commentedThe patch for 9.2.x in #267 worked for me too. Thanks!
Comment #270
rcodina CreditAttribution: rcodina commentedComment #271
patrick.thurmond@gmail.comI had to use the 8.9.x #267 patch today. Works great. Why is this not merged yet?
Comment #272
dagmarBecause this feature need Tests.
Comment #273
rcodina CreditAttribution: rcodina commentedIt has been 6 years so far since this issue was created. Still today, a feature available on Drupal 7 is not yet ready for D8 and D9. Could anyone add tests please?
Comment #274
dagmarReading the entire thread in addition to tests it seems the comment mentioned here #2457999-225: Cannot use relationship for rendered entity on Views needs to be addressed as well
Comment #275
joelsteidl CreditAttribution: joelsteidl at Aten Design Group commentedThe patch for 9.2 in comment #267 worked for me.
Comment #276
danflanagan8I want to help write the missing tests here. Here's a patch that triggers the error mentioned in the IS. What other test cases are missing?
Comment #278
jonathanshawLooks like we're still missing a fix for the original bug :)
Additional tests needed are discussed in #225.
Comment #279
danflanagan8The patch for 9.3.x in #267 does fix the failing test I posted in #276. I just didn't post a combined patch because without the other missing tests it's not especially useful.
Comment #280
danflanagan8@plach,
I do not understand the relevance of the View referenced in comment #220. I just spun up a D8.9.x site with the db dump and this is what I see for that View, no patch applied.
This View doesn't show Content, it shows Fields. And I haven't applied any patches for this issue that would have possibly caused this language bug as a regression. There may be a bug here, but I don't see how it's related to the issue at hand. Does the IS need a major update? Has the scope increased significantly?
I want to help get this committed but I just don't understand what kind of tests we're looking for.
Comment #281
danflanagan8After reading through #2313159: [meta] Make multilingual views work and #2446681: Error "Column 'langcode' in field list is ambiguous" thrown due to TranslationLanguageRenderer not rendering a field from a relationship a bit, it looks like this is has become the de facto issue for fixing how Views handles finding the correct translation for a relationship. The IS should probably be updated here to make that goal clear. In the meantime, here are the long-awaited tests for multilingual relationships with either the Field row or Entity row, as well as the test that exposes the UI bug detailed in the IS.
I'll post the patch from #267 to run against the new fail tests as well. The interdiff attached is equivalent to the 9.3.x patch from #267.
Comment #282
danflanagan8oops. Let's try again without the extra whitespace.
Update to highlight test failures:
First failure was the bug described in the IS:
Third failure was the bug pointed out in #220 related to incorrect handling of "Original language of content in view row" (
***LANGUAGE_entity_default***
) when using relationships:The second failure is related to the Entity row plugin, but I don't know if it has specifically been discussed anywhere. I don't have anything special to say about it.
Comment #284
danflanagan8And perhaps as the final touch (maybe?), let's address the remaining concern from #225 related to
getEntityTranslationByRelationship()
.Comment #285
danflanagan8Comment #286
Javier_Rey CreditAttribution: Javier_Rey commentedComment #257 is right, applying this patch breaks the functionality of the "Alternating View Mode" display suite module. I have tried to modify both the module and the core but I can't get it to work, any alternative solution?
Comment #288
alvarito75 CreditAttribution: alvarito75 commentedConfirming patch #284 working well in core 9.3.7 for me after upgrading from Drupal 8.9 and applying this patch.
Comment #289
tonytheferg CreditAttribution: tonytheferg commented282 worked for me. For some reason 284 would not apply. I do have some other views patches though. :\
Comment #290
SocialNicheGuru CreditAttribution: SocialNicheGuru commented#284 worked for me.
Comment #292
alayham CreditAttribution: alayham at University of Gothenburg for Aljaml.com commented#284 Works for me on 9.5.x-dev
Comment #293
alexpottOver the years our standards have changed for typehints etc... so I'm updating the patch with the latest standards for 10.x and 9.x....
For me the 1 remaining question is should we be deprecating \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslation() here - I'm not sure.
Comment #294
alexpottDiscussed with @Lendude. We agreed that this should be 10.1.x because it has cuase contrib breaks in the past so this is too late for 9.5.x/10.0.x. Given that we should deprecate
\Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslation()
in favour of\Drupal\views\Entity\Render\EntityTranslationRenderTrait:: getEntityTranslationByRelationship()
- we'll need another change record for this specific change. Given the change is to:I don't think we need specific test coverage of the new deprecation message - unless adding a test is super simple.
Comment #295
LendudeSecond CR https://www.drupal.org/node/3311862 for the deprecation, I'll roll a patch to use it
Comment #296
LendudeDeprecation added.
Comment #297
jonathanshawThe test fail is simply that the deprecation message added in #296 should read "removed from" not removed in", I've tagged this for a novice fix.
I'm setting to RTBC anyway as that best describes the state of the issue at this point, apologies if that's a misjudgment.
Comment #298
Lendudein => from
Comment #300
LendudeDeprecated function was still used in core, could only find one occurrence still, lets see if that fixes it.
Comment #301
jonathanshawNice
Comment #302
alexpottCommitted eb019c1 and pushed to 10.1.x. Thanks!
I tried to get the credit right - if I've made a mistake please let me know.
Comment #304
Petr IllekWould this be merged into 9.x as well?
Comment #305
longwave@Petr Illek please see #294 - you might be able to use the patch from #293 against 9.5.x, but it will not be present in a released version until 10.1.0.
Comment #306
andres.torres CreditAttribution: andres.torres commentedThank you all for the hard work here! this is so very helpful!!
Comment #308
Anybodyhttps://git.drupalcode.org/project/drupal/commit/eb019c1.diff (which was committed in #303 indeed works against 9.5.x - thanks! :)
Comment #309
david.muffley CreditAttribution: david.muffley commentedWhile this is closed and committed to 10.1.x, #308 and #293 no longer apply to 9.5.1 due to surrounding changes.
Here's a re-rolled patch for those of us who still need it for 9.5.x.
Comment #310
grantkruger#309 worked for me on 9.5.2. Thank you david.muffley!
Comment #311
nicklundy CreditAttribution: nicklundy at Millennium Communications commented#309 also worked for me on 9.5.2. Thank you!!
Comment #312
super_romeo CreditAttribution: super_romeo commentedIs there any patch for D10.0?
Comment #313
liquidcms CreditAttribution: liquidcms commentedconfirming that #309 works on D9.5.8, the earlier patches did not.
Comment #314
doxigo CreditAttribution: doxigo as a volunteer and at Ramsalt Lab commentedAlso confirming that #309 works on Drupal 9.5.8, this needs to be committed to 9.x as well
Comment #315
ChrisSnyderIs this still an issue for Drupal 10.0?
Comment #316
LendudeSee #302, committed to 10.1, so anything earlier will not have this fix
Comment #317
LendudeSee #302, committed to 10.1, so anything earlier will not have this fix
Comment #318
joegraduateRe-rolled patch #309 for 10.0.x.
Comment #319
32i CreditAttribution: 32i commented#284 worked for 9.4.x
Comment #320
LRoelsI traced issues of a DS ticket back to changes in this ticket.
The issue in question is this one: https://www.drupal.org/project/ds/issues/3394419
Anyone that could take a look to see what the issue could be?