Problem/Motivation
When nodes exist with translations, duplicate copies of them appear in views, rendered identically. Eg. on stock Drupal 8 enable Content Translation module, create articles with translations (configure translatability on Configure > Regional and language > Content language and translation). Translate an article to at least one language. The article will show up on the front page multiple times with the same content.
The article does not show up the same way in the admin view for example, it shows multiple times but with the right language. (It uses a field row plugin which triggers the render controller and entity language negotiation).
Proposed resolution
Separate issue
In this issue, ignore that there is no explicit language filter in the front page view. "Current page's language" (current user's language ) views filter (#2037979: "Current user's language" views filter label is named very misleading) could filter the results, however that is from an optional core module, and magic views filters popping up have been an issue before. Another issue can work on changing the front page filter so that it only shows one version of each node. This may be tricky as it might involve more complicated filters which allow fallback in cases where results are not translated into the language being filtered for. To be done in #2161845: Node views (front page, admin) do not use the proper language filter. Maybe with later improvement from #2161853: Add views language filter fallback, if node not in language of filter: show in source, show in X, hide.
Fix/Focus of this issue
Without a language filter, Views shows all the results (so node variants in all languages). This is fine.., except views is (incorrectly) using the current page's language when rendering all of them, so shows each result is rendered into the same language (showing identical duplicates). We fix this by showing in the language found and not rendering each result into the current page's language.
Before, and after applying the patch #131:
The patch adds a new views rendering setting to achieve this and still keep flexibility for rendering with language fallback. If you don't reinstall Drupal after the patch don't forget to check the new setting in your Views. In section FORMAT click the selected View mode (in this case Teaser) and set the Rendering language to Translation language if needed.
Remaining tasks
Commit.
Steps to reproduce
- install
- enable content translation
- add a language
- configure content language settings ... to enable translation on content, articles
- create content (article)
- translate content
- go to home page, see two (displayed in the same language)
- switch languages, see two (displayed in that language)
User interface changes
New views rendering setting.
API changes
No changes.
API addition: \Drupal\views\Entity\Render\RendererBase
added to encapsulate definition of how an entity is rendered in Views. Implementations \Drupal\views\Entity\Render\TranslationLanguageRenderer
and \Drupal\views\Entity\Render\DefaultLanguageRenderer
as well as \Drupal\views\Entity\Render\CurrentLanguageRenderer
are added to cover different language rendering use cases.
Comment | File | Size | Author |
---|---|---|---|
#163 | interdiff-2006606-159-163.txt | 4.28 KB | YesCT |
#163 | 2006606-language-view-duplicate-163.patch | 22.66 KB | YesCT |
#158 | 2006606-language-view-duplicate-158.patch | 22.68 KB | plach |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedComment #2
plachThis is a known behavior, see #1498674-213: Refactor node properties to multilingual. We need some kind of language filtering in the front page view. This is the quick fix. The real fix is making Views using EFQ and handle language filtering from there.
Comment #3
Gábor HojtsyDrupal core did this forever. Depending on what you want on your front page this might or might not be an issue. The frontpage did not use to be language filtered in any Drupal version so far :)
Comment #4
klonosYes but then again, Drupal core didn't used to be multilanguage capable/aware before D8 and nor was the front page a View ;)
Being able to (optionally and configurably - is this a real word btw or did I just invent it?) filter by language is a thing that D8 needs to do (Views, Search results etc).
Comment #5
plachThe difference with what happended in the past is that now you have two identical nodes (due to content language negotiation), where before you had two different translations. This is not something we can leave as-is.
Comment #6
Gábor HojtsyI agree it is more likely a default assumption that posts in the same language should show up. Either way it sounds like something we should set up in the default view and people will be able to modify :)
Comment #7
plachYep, I think a quick and easy fix would be using
node_modules_enabled()
to add a node language filter set to "current language" or "language not specified" when entity translation is enabled.In the long run when Views will use EFQ this won't be needed as EFQ already selects unique entity ids. Language filtering could be added by those actually needing it.
Comment #8
Gábor HojtsySounds like to me a language filter is useful even if no entity translation? To filter for nodes in specific language. So make it go right into default view?
Comment #9
plachThis will slow down the query on monolingual sites. Maybe we can react to Language module being enabled instead?
Comment #10
YesCT CreditAttribution: YesCT commentedEnglish monolingual sites do not have language module installed..
but non-english monolingual sites do have language module installed, .. right? I'm pretty sure that language module is enabled when installing for example in Spanish, as I was doing to test something else last night.
Which of the other node properties follow-ups to the queries might this be related to? Maybe #2004372: Refactor node query to use desired language rather than default language while providing fallback to default?
(The follow-ups were our best guesses, but will need some clarification so people can know better what effect they will have.)
Comment #11
devuo CreditAttribution: devuo commentedThe problem actually originates from either a filter or a sort handler in views that joins a translatable field in a given entity. Given that there will be a row for each translation of that entity in a translatable field, the query will return multiple results. The only way to fix this is to add a WHERE condition to the field table JOIN in the field filter/sort handler to filter out results where the language column doesn't match the desired language.
Comment #12
YesCT CreditAttribution: YesCT commentedran into this while helping update the issue summary of #2004626: Make non-configurable field translation settings available in the content language settings
with that patch, the titles are different for the duplicates in the content list...
Comment #12.0
YesCT CreditAttribution: YesCT commentedadded missing step to enable translation on articles
Comment #13
Gábor HojtsyUpdated issue summary, title and added VDC tag.
Comment #14
plachIMO the proper solution for this issue should be exposing
node_field_data.langcode
as a "Translation language" views field and add an optional filter based on it which would filter stuff based onLangcode::LANGUAGE_NOT_SPECIFIED
/***current language***
.Comment #15
Gábor Hojtsy@plach: I think that may be a stop-gap, but generally Views should be aware that it may display an entity in different languages, and not always use the page negotiated language. I guess Views needs a setting to apply the negotiated language (and then DO FILTER) or not apply that and then do render in different languages. By default it should probably filter, but that is not an overall solution for the views cases it needs to cover.
Comment #16
plachI think we should avoid automagic as much as possible: we should give people the way to implement whatever use case they need without getting in the way.
What about having an option on the node row plugin where the user could choose which language to use to render the entity? For instance 'italian', 'current language', 'translation language', 'node language' an so on.
My suggestion of applying an optional filter was just related to the node front page and the content admin.
Comment #17
Gábor HojtsyYeah an option on the node row plugin works as well.
Comment #18
dawehnerComing from D7 we have inherited the concept of field language.
On each view you could select one of the three options:
This information is used to filter the fields, when they are displayed.
@Gabor There was one issue which added some of the new language types there, do you remember the issue?
I wonder whether the entity row plugin should just use the option which is currently called field language to figure out which language to use
for loading? Maybe we should then also rename the option.
Comment #19
Gábor Hojtsy@dawehner: that would be #2037979: "Current user's language" views filter label is named very misleading.
Comment #20
Gábor Hojtsy@dawehner: I think filtering is not the only solution here. While that solved the problem itself, if you want to filter for more than one language, then the rendering would still happen in the page negotiated language for all of them, so the rendering of the node itself also needs to be potentially different based on views settings. For a view that displays entities from multiple languages, the same entity may need to be displayed in multiple languages.
Comment #21
plachConsidering the use case in #20 we would need an additional option, that is the translation language (
node_field_data.langcode
), which would allow us to render each row in its own language.And I think filtering needs to be explicit :)
Comment #22
Gábor Hojtsy@plach: in fact I think given what we explored above #21 is what should be done. Then IF the view is filtered, you would get node's where node_field_data.langcode is the one being filtered for, so naturally you would see that displayed. If you filter for multiple languages, the right ones would display. If you filter for the page negotiated language, only nodes for that language would display (rendered in their proper language), etc. So views should take the language of the entity variant found and NOT the page's language. If the page's language was used in a filter, that will have the proper effect already.
Am I missing something?
Comment #23
plachNo, it's ok, I was complementing your answer to Daniel :)
Comment #24
hass CreditAttribution: hass commentedI do not think this is normal.
Comment #25
Gábor Hojtsy@dawehner:
Right, views should render the node in the language it found it :) Then filtering will probably be yet another (different) issue. We already have #2037979: "Current user's language" views filter label is named very misleading which deals with naming the filters and then we can open yet another issue to add filters to some views when translation is enabled (and debate the validity of that magic there).
I think the full scope of this issue is the rendering of the node in the language views found it, so that should be a small enough scope to not drive lots of bikeshedding :)
Comment #26
plachSo basically we would restore the D7 behavior and all node translations would be shown?
Comment #27
dawehnerThis is just the first work on the issue.
Comment #29
plachlangcode
should be picked from the data table (if it exists).Comment #30
Gábor HojtsyLooks like some random PHP ended up in the code...
Comment #32
dawehnerAdressed the feedback of plach.
Comment #34
Gábor HojtsyThe error seems to be
Undefined property: Drupal\views\ResultRow::$langcode
:/Comment #35
Gábor HojtsyInstead of using the langcode property on the row (which is not there), we should use the langcode alias :) Thanks @dawehner for pointing that out :)
Comment #37
Gábor HojtsyAnother misused variable :D
Comment #39
Gábor HojtsyNow only actual fails :) In node translation. I'll not have time to look into this anymore this week unfortunately, so @plach / @dawehner feel free to pick it up :)
Comment #40
vijaycs85Attached patch solves duplicate display but not sure whether it is right approach as we are not doing anymore >1 language check.
Comment #41
dawehner:( I would like to keep the viewMultiple functionality.
Comment #42
dawehnerSo what about doing something like that?
Comment #44
vijaycs85missing pointer
$$?
Comment #45
vijaycs85Updating...
Comment #46
Gábor HojtsyTested and the language rendering behaviour looks good (ignore that the body is always the same that seems to be a current core bug, heh).
However, the links on all nodes lead to the node in the language of the page instead of the language of themselves. That may not be a bug in Views I suppose. Either way, we should back this up with some tests :)
Comment #47
Gábor HojtsyOpened #2148795: Configurable field translatability is not properly switched about the body problem. Not caused by or related to this issue. Not sure if the links should be / possible to be fixed here or not.
Comment #48
dawehnerRegarding the links I guess we need something like the following? This feels a little bit out of scope for that issue to be honest.
Comment #50
Gábor Hojtsy@dawehner: indeed that seems to be its own issue. In fact I opened #2149649: Entity rendering/theming does not use the active entity language to render links and put your patch there :) So this only needs tests then? :)
Comment #51
vijaycs85ok, Patch in #45 is still applies and issue that #48 tries to fix has it is own issue (ref: #50)
Comment #52
Gábor HojtsyI think this would be good to go as soon as we have tests :) I think this is a very important piece of functionality for multilingual, so people can create views that make sense for them :)
Comment #53
Gábor HojtsyComment #54
vijaycs85Updating the test case to cover this issue.
Comment #55
Gábor HojtsyThat looks sweet and simple if it works :)
Comment #57
Gábor HojtsyYay, amazing, thanks!
Comment #58
Dries CreditAttribution: Dries commentedI don't fully grok the patch yet but it seems like a weird solution. It looks like the problem is that viewMultiple() is not capable of handling multiple languages and so we have to work around that. Wouldn't it make more sense to move this logic to viewMultiple() / entity_view_multiple() so users of that API don't have to use similar workarounds? Can't help but feel we're fixing this in the wrong place.
Comment #59
Gábor HojtsyComment #60
webchickAdditionally, the patch doesn't seem to work. :\ I applied the patch, followed the instructions in the OP, and still see duplicate nodes.
Comment #61
YesCT CreditAttribution: YesCT commentedTried this manually, following steps in issue summary,
without patch on current head:
with patch, each is shown in its own language, better!
Talked with Gabor in irc earlier. This behavior is ok for now. Changing the default frontpage view to add a language filter would be a separate issue. Also, other more complex kind of views would be possible with help from contrib (like fallbacks if a node exists, but not in the language of the page).
double space, fixed.
clarified it is checking for each translation title. this test works because above, translations are created with random titles, so clarified what is being tested.
missing doc block.
it is missing in too RowPluginBase, but that is a different issue.
added inheritdoc and opened issue #2160797: Add missing doc blocks in RowPluginBase.
Still needs work for Dries's comment in #58 (also a @todo about viewMultiple() )
Comment #63
vijaycs8561: 2006606-language-view-duplicate-61.patch queued for re-testing.
Comment #64
victor-shelepen CreditAttribution: victor-shelepen commentedI've applied your patch. But it does not work on my side.
I see it does not filter language items. I though entity translation almost in core. I see Different translation use the same nid. It is right. But why views do not filter it?
Comment #65
victor-shelepen CreditAttribution: victor-shelepen commentedt is very interesting. entity_view_multiple returns the right quantity of entities. But Views ask renders duplicates.
Comment #66
victor-shelepen CreditAttribution: victor-shelepen commentedEntity is an atom of a new Drupal system. Here we split atom into subatoms :) I see how the last patch works. It looks like on the old Drupal way. When we had a node translation by creating another related node. They existed as separated nodes. As for me I do not like this way. I can not find a way how views split it.
Comment #67
Gábor Hojtsy@likin: *you* can add a language filter to your front page view. Drupal does not have this filter. This bug is about fixing the case when the view does not have such a language filter. We cannot just assume all views will have a language filter of some kind and if they don't, then you get this bug. If you do filter down your view to a language, then you'll not notice this bug because this bug is about the same node matching the view in different languages and then rendered improperly. Clearer?
Looks like this may have been @webchick's misunderstanding as well? Maybe we need an issue summary update because the stop-gap in the issue summary is NOT what is implemented in this module based on extensive discussion above.
@YesCT can you help with a clear issue summary? :)
Comment #68
victor-shelepen CreditAttribution: victor-shelepen commentedFor my case this hack works for any multilingual "views". It look on a workaround way.
I guess that I am wrong because I do not see a whole picture. But I looked over the code, the query object. I found out that it used LEFT joins with the node_revision table. It multiplied nodes.
I wait for a right solution. :)
Comment #69
Gábor Hojtsy@linkin: right, if you *never* *ever* *under any circumstances* want to *ever* display the same node in multiple languages in the same view, then your workaround "works". If in any case, you need to display an entity translated to more than one language in the same view, then you'll hit this bug, so we are trying to resolve it. :) As an added bonus, the front page view as-is is exposing this bug big time, so it is pretty visible.
Comment #70
webchickAn issue summary that explains what the actual problem is we're trying to solve here and how would definitely help, but I don't understand why we wouldn't make #68 the default (it's certainly my expectation when I filter to "french" i will see french content and not english content on my site), so maybe include that in the issue summary as well. :) Or, ideally, fix it, to match user expectations.
Comment #71
klonosYeah, but there are actually two cases of "filtering" depending on what meaning one might give to that:
1. filtering French so that French content is shown and untranslated content gets hidden. IOW: show only French - hide the rest.
2. filtering French so that French content is shown and content not yet translated in French is shown in the language it was originally created. IOW: prefer French but show all (a.k.a. language fallback).
IMHO, because this is a matter of per-site and some times per-view preference, we should provide an option to define what people want to do with untranslated content. So, two options: "Hide it" and "Show untranslated original"
If we wanted to make it clear(er) why non-French content is shown when people choose to show untranslated too, we could append (optionally again) "not translated in [selected_language] yet" next to titles. That text could become a link for users with appropriate permissions to take them to the translation page for that piece of content for the specific language. Sounds like a reasonable workflow to me.
Comment #72
dawehner@webchick
We will show all translations, unless someone adds a filter in views. Views in general went from magic in D6 to more explicit behavior in D7 and the response was really positive. What this issue solves is just the rendering in the right language. Please please don't be confused by comments of people.
Comment #73
victor-shelepen CreditAttribution: victor-shelepen commentedYou bother about case when some content is not translated. So it shows all articles with default language. If an article is not translatted comletly it can use a translation from predefined source. Multilingual Entities work well . it does not reduce nodes if they do not have.
I call views - visual entity query manager. Why we modify views lets modify entity api.
Comment #74
victor-shelepen CreditAttribution: victor-shelepen commented@klonos views does not hide untranslated nodes. I've checked. Views uses entity-load-multy it works well. It always returns nodes without duplicates. Every entity has a getTranslation method. Look the last patch. It works but it looks on the workaround method.
Comment #75
BerdirThere are two "problems" with the frontpage view, as the title already says. It displays duplicate *and* identical nodes. This issue currently only solves the problem that *identical* nodes are displayed.
This is because views completely ignores the language and renders any entity in the current content language. This is a simple problem, and you best ignore the current frontpage view configuration, or multiple translations of the same entity use case for now. Consider the use case where you want to display a list of french nodes, then they should be shown in french. However, if you do this right now, you would get them in your current language, if available. This patch changes them to respect the language but currently doesn't consider the fallback, I think, see blow. The result is that entities are in the right language now, but we still have th second part of the problem:
The second "problem" is the duplicated part. And while it's true that there are many use cases for it and that views should absolutely support it, I think it would really make sense to have a better default configuration for the default frontpage view, this issue is proof that the current default confuses people. And those that want to see them all can easily re-configure the view. It's also easier to remove the condition rather than add it?
Maybe we should open a separate issue for that and re-title this issue to something more simple, like "Views rendering does not respect/ignores entity language"? Because while I perfectly understand the arguments made by @dawehner, @GaborHoitsy and so on, the patch does *not* solve the problem described in the issue title.
This doesn't consider language fallback. Should we use EntityManager::getTranslationFromContext() here to support the use case "show current language of all entitites or best available fallback"? Or does views already have the correct langcode? I think not?
Should we name this $translation or $entity_translation? Re-using $entity is a bit weird within a foreach loop.
Entities in viewMultiple() are keyed by the entity ID, while #2073217: Remove the $langcode parameter from the entity view/render system would allow to set a language per entity, the real problem is that we don't support to render the same entity in multiple languages, even with that. Not sure what to do about that.
Comment #76
victor-shelepen CreditAttribution: victor-shelepen commented#75++
Comment #77
YesCT CreditAttribution: YesCT commentedupdated issue summary.
Added related issues.
Comment #78
klonos@YesCT: Thanx!
Comment #79
plachI totally agree with @Berdir that the current behavior is not the most sensible default, although we need to support it. If we do not want to postpone this to #2073217: Remove the $langcode parameter from the entity view/render system, to address @Dries' feedback we need to remove the
::viewMultiple()
call and go with just::view()
(sucks).This needs to take into account also the revision table. Fixed in the attached patch. Setting to needs review for the bot, although this is still needs work.
Comment #80
plachComment #81
plachComment #82
plachAlso, we should make the render language configurable, otherwise no kind of fallback based on the current language would be possible, I am afraid.
Comment #83
Gábor HojtsyUpdated the remaining task to say "Figure out if we can make this behavior work in viewMultiple()." only. That sounds like would require other changes in the entity system (if at all possible). Eg. so we can pass in that we want the entities to be rendered in the language found (instead of taking the language from elsewhere). Is that in scope for this issue and if not, are the changes here useful regardless? I mean the actual line changes. I think the bugfix as-is is very valuable.
Comment #84
Gábor Hojtsy@plach: I'm not sure what you mean there? Fallback in the query? In rendering? What would the options for that setting be?
Comment #85
Berdir#83: I think changing the entity render system here is definitely out of scope and not trivial. There's #2073217: Remove the $langcode parameter from the entity view/render system, the parent issue it relates to (which still need to be updated) but as I mentioned, the problems for this specific issue (rendering the same entity in different languages) go even deeper, as mentioned above (it assumes that the list of entities is keyed by entity id, which would no longer be possible)
Comment #86
Gábor HojtsyWhich makes the current patch RTBC again, no? @plach?
Comment #87
plachA follow-up issue was added to introduce support for language fallback: I don't think we can implement that at query level in an efficient way. if I were to implement such a view today, I'd just create it with a distinct clause and I'd be done: entities would be rendered in the current language or would fall back to another language, if no translation for the current one existed (I manually tested it).
This issues currently makes supporting that use case impossible, as it hardcodes the translation language as rendering language. If, as discussed above, we had a selector in the entity row plugin to choose the rendering "strategy" we could support both. The available options might be:
I am available to implement this ASAP if you are ok with it, but I don't think this is good to go as-is.
Comment #88
BerdirAgreed that enforcing the selected language without a way to change it is problematic, that's what I meant in #75.1.
Comment #89
plach@Gabor:
Are you ok with the plan outlined in #87?
Comment #90
Gábor HojtsyI don't see how *this* patch makes supporting that use case impossible. It is not possible to support now either. The rendering does not pass on any information to tell if the entity was a duplicate render, or if its rendered in views or even a suggested langcode for rendering... So I don't see how that use case would be possible *without* this patch either. I contest this patch makes it any harder to implement. Either way it requires further changes, no? The question is just keep that unsupported for a little while more while letting this bug fixed or get more features into this bugfix.
Comment #91
plachIn the current HEAD you can configure the front page to perform entity translation fallback on rendering by just enabling the "Distinct" option in the query settings. You can see the result in the three "head" PNGs you can find attached. Apply this patch and you get what you can see in the "patch" PNG, that is the distinct query no longer works, as we are hardcoding the translation language field in the select.
You can find also my test db and files if you want to see this in action.
My point is that with the current patch we are fixing one use case and breaking another one, which IMHO is more common, and I strongly believe we should support both.
Sorry if I am missing something, but I really don't see the point of committing the current patch as-is.
Comment #92
Gábor HojtsyYeah let's add options then...
Comment #93
plachCool, I will do it tonight, if no one else beats me to it.
Comment #94
plachThis adds the selector in the row plugin settings to choose the rendering strategy. It adds a new entity renderer class that should obviously a new plugin type, but since I wasn't sure it's worth the effort, this patch instantiates them statically.
If Daniel is ok with this approach we just need to make them plugins, which should be pretty trivial, otherwise we can collapse them back into the
EntityRow
plugin.Comment #96
plachI will fix tests once I have a feedback on #94.
Comment #97
Gábor HojtsyComment #98
dawehnerFrom the pure code perspective it totally make sense to separate the different usecases of rendering into several classes. I wonder whether there is any need for contrib to override this behavior. If yes I wonder whether entity list controllers have a similar problem.
Comment #99
plachNot sure whether there are use cases to override those behaviors, but maybe adding new ones could make sense?
Gabor, what do you think?
Possibly. But I think that for those a default sensible behavior could be enough, as they are not configurable.
Comment #100
Gábor HojtsyI think adding more options/plugins like this would be potentially useful, not sure about overriding. If you can add more, you can add another option and just update your view, so you can effectively do the same thing.
Comment #101
plach@dawehner:
So, ok for plugins?
Comment #102
BerdirCan we look into making them plugins in an follow-up issue that is not a major bug and go with a quick fix here?
We already have a crazy amount of plugin types (which currently results in tons of cache get requests) and I'm not sure there are other options here?
Making something that is currently harcoded extensible/pluggable shouldn't be an API change for existing code, so we wouldn't need to hurry something in...
Comment #103
plachDo you mean just cleaning-up the current code and keeping separate classes or removing them and possibily introduce plugins in a followup?
Comment #104
plachThis should clean up PHP docs and fix failures.
Comment #105
plachMmh, no
Comment #106
Gábor HojtsyI'm concerned that by default this will not be the default behaviour of the view. Also not the default behaviour of a view created later. So by default core will still have the same "bug" that is has now :/
Any todo added should be qualified with a URL :)
Should have an interface for this as well, so those not implementing derivatives from rendererbase would still be forced to implement the proper interface, no?
Comment #107
Gábor HojtsyComment #108
plachThe attached patch should fix #106, except for #3: I don't think it makes sense to introduce an interface while renderers are still hard-coded. It would just mean more boilerplate code and I/O, since we are not using type-hinting anywhere.
I added a @todo to go back to the current language renderer as default as soon as we have a translation language filter, which I think makes more sense a default behavior. Or at least we should do that for the front page view (this is why I retained the changes to the node translation test).
There is also some code clean-up since hard-coding class names made my eyes bleed :)
Comment #109
plachComment #110
plachQualified another @todo.
Comment #111
Gábor HojtsyLooks good to me. I understand your point of view that we don't need an interface so far as we hardcode it and we should add it later on. I think we should get a Views OK on this and get it in :)
Comment #112
dawehnerWe can always add the interface later. Views itself though don't really leverage interfaces yet.
This code looks fine, just a small nitpick here.
Should we just typehint the LanguageManagerInterface
Comment #113
BerdirThat interface only exists since a few hours, it has been added by #1862202: Objectify the language system. So yes, we can do that *now* :)
Comment #114
plachFixed #112 :)))
Comment #115
plachIt seems all concerns were addressed or have a follow-up. Back to RTBC?
Comment #116
Gábor HojtsyContainer::camelize seems like a bit of magic, but its internal so, ok.
Why do we need the \\ though? My only concern left :)
Comment #117
plachBecause a single backslash would escape the closing single quote and you'd get a syntax error because of the unclosed string literal.
Comment #118
Gábor HojtsyOMG right :) So looks good. Resolved the multiple view problem, has options and stuff and @dawehner and others also liked it :) What else would one need? :)
Comment #119
dawehnerUnassign from me
+1 to the RTBC
Comment #120
damiankloip CreditAttribution: damiankloip commentedIf this is not a plugin, it should not be living in the plugin namespace. Also 'rendering' is a strange sub namespace, why not just render?
Seems like a better idea to pass in the view instead of the row plugin?
Needs some sort of @return
It's weird that a 'renderer' has a query method on it.
Why not just use the entity again? if a row plugin decides to not call the parent query method, it will break this I think?
Could just return array() here.
@return
$this->t()
All of this code but just this test coverage in a web test? Seems a bit scant... Also all this code is added to views, but this little bit of coverage is in node module.
Also, do we always assume an entity langcode will always be 'langcode' in its schema?
Comment #121
damiankloip CreditAttribution: damiankloip commentedComment #122
plachThanks for the review, this should address #120, except for:
Setting needs review for the bot.
Comment #124
damiankloip CreditAttribution: damiankloip commentedThis is only an assumption from entities that extend ContentEntityBase?
2. But it's the EntityRow plugin that is using this. So that's not really possibly. Unless we are expecting people to try and do crazy things with this?!
4. It is just strange having something that works kind of like the query() method of views handlers, but not quite.
5. If for some reason a row plugin using this does not call the current code in RowPluginBase::query (which adds field_alias for the base field) then that code break straight away.
6. I'm not sure what sort of dependencies the language part of this patch has? We have base test classes for web tests and DUTB tests in views :) As usual, a DTUB test would be good.
Comment #125
Gábor Hojtsy@damiankloip: I think the assumption from entities that extend ContentEntityBase is to be resolved with #2143729: Entity definitions miss a language entity key, entities lack a key for language, so we need to hardcode it for now.
Comment #126
plachThis fixes also #120.2 and #120.6, not sure what to do about #120.4.
Comment #127
plachRemoved unused variable.
Comment #128
Gábor Hojtsy@damiankloip started working on #2143729: Entity definitions miss a language entity key there, not to be solved here :)
Comment #129
plachSome more code clean-up :)
Comment #130
dawehnerGood points from damian before, thank you for the review.
Let's call it "The view executable" or something else. The top object does not describe anything. What about "The view exeucutable which is set onto the entity"
You can also just put on there {@inheritdoc}
Comment #131
plach1: I tried to make it as explict as I could and fixed another PHP doc.
#2 was already fixed in #127, I forgot to mention it, sorry.
Hope this looks ok now :)
Comment #132
pedrop CreditAttribution: pedrop commentedComment #133
dawehnernice!
Comment #134
pedrop CreditAttribution: pedrop commentedComment #135
pedrop CreditAttribution: pedrop commentedComment #136
pedrop CreditAttribution: pedrop commentedComment #137
pedrop CreditAttribution: pedrop commentedTested and added some screenshots.
Comment #138
roderikAnd immediately using the description/screenshot while looking at #2149649, thanks :)
Comment #139
plachJust a reroll
Comment #140
plach139: 2006606-language-view-duplicate-139.patch queued for re-testing.
Comment #142
plachUpdated the new test after #2047633: Move definition of menu links to hook_menu_link_defaults(), decouple key name from path, and make 'parent' explicit.
Comment #143
plachThe change was really minor so I think i'ts fair to move this back to RTBC.
Comment #144
dawehner+1
Comment #145
alexpottComment #146
plachRerolled
Comment #148
Gábor Hojtsy146: 2006606-language-view-duplicate-146.patch queued for re-testing.
Comment #150
segi CreditAttribution: segi commentedI tested by patch in comment 146. But I got a php error on the front page:
Fatal error: Call to a member function get() on a non-object in core/modules/views/lib/Drupal/views/Entity/Render/TranslationLanguageRenderer.php on line 34
Comment #151
pfrenssenGoing to take a look at this.
Comment #152
pfrenssenUpdated the patch:
In user_attach_accounts() if an anonymous user was being attached to an entity, it was using a UserSession object rather than a User object. Apparently there was no test coverage for this. This is now indirectly covered in RowEntityRenderersTest, but we might want to open a followup to add a specific test for attaching anonymous users to entities.
There was a confusion between using a full EntityType object, or just the entity type as a string in the rendererBase. I chose to use the object, as this can be type hinted by PHP and it will throw exceptions when a string is passed by mistake. This is more error proof than using strings.
I am currently blocked on a test failure in RowEntityRenderersTest. When it is rendering the nodes and tries to retrieve the node URL in
template_preprocess_node()
it throws:It is not clear to me why this route should not be available. The Entity::url() method it relies on has been added recently (in #2167641: EntityInterface::uri() should use route name and not path), but I reviewed the code in that issue and it does not seem to be the cause of this.
Comment #153
pfrenssenLet's see if the bot also has trouble finding the node.view route.
Comment #155
YesCT CreditAttribution: YesCT commented152: 2006606-language-view-duplicate-152.patch queued for re-testing.
Comment #157
plachThis should fix the exception
Comment #158
plachThis should be better as it also fixes the renderable array returned by the default language renderer (test-coverage provided by the removed lines in the interdiff test hunk).
Comment #159
Gábor HojtsyYay, thanks for unbreaking this. This one would be one important baby to get into core :)
Comment #160
YesCT CreditAttribution: YesCT commentedWe should look and verify that the tests it needs were added (and remove the needs tests tag),
and check if the proposed resolution section of the issue summary needs updating (and remove the needs issue summary update tag).
Comment #161
Gábor HojtsyComment #162
Gábor HojtsyUpdated the issue summary. The patch also has tests for both the UI rendering of the front page and specific tests for the newly added language rendering options in views.
Comment #163
YesCT CreditAttribution: YesCT commentedI read all the lines in this patch.
tested this manually again and it still works well.
I dont see this used anywhere. Why add this empty class?
Hmm...
I see the name was changed in #122
and its use taken out in #108, when the todo for #2161845: Node views (front page, admin) do not use the proper language filter was added.
I left it in and did not take it out.
could be third person verb like:
Renders entities...
I changed a bunch of these.
Should probably be:
Alters the query if needed.
missing description
I added a description.
missing type.
added bool
seems like this should be 0 or false after #2167623: Add test for all default configuration to ensure schema exists and is correct maybe some other types also can be more accurate.
I did not change these.
I was going to add @covers for phpunit tests, but when I ran the tests before and after the patch, it didn't change the number of tests run... then with help from irc, noticed that this is TestBase (not TestCase). :)
I guess the only thing that might have been minimum core gate was just the one type missing on the return.
Comment #164
Gábor Hojtsy@YesCT:
1. CurrentLanguageRenderer is one of the views render options added by the patch, it is exposed on the UI in views. This is used.
2-5: thanks!
6. All the test views have offset: '0' already in core on their pagers. Almost 30 of them :) Should be good as-is.
Back to RTBC then :)
Comment #165
webchickOk, ran through my testing again. Before the patch: "/" shows "English marrrggh" twice, "/fr" shows "French marrrghh" twice. After the patch, both views show "English marrrgh", "French marrggh" in that order. I commented that this was not particularly an improvement. :P But Gábor correctly pointed out that what this does is restore D7's behaviour.
Therefore, committed and pushed to 8.x. Thanks! Let's move ahead with the other follow-ups we found while testing this one. :)
Comment #166
damiankloip CreditAttribution: damiankloip commentedIs there a follow up to clean up this lurker? This is kind of nasty (which was mentioned already), plus no one can add their own 'renderer'.
Comment #167
BerdirI don't think there's a follow-up yet. I'm not sure if there is a useful different way to render an entity, not sure if it really needs to be pluggable, but happy to discuss that :)
I wanted to clarify one more *why* we did this change. It's not about making this work the same way as it did in 6.x, that was quite a different situation and is only a side effect of this change and we have a follow-up in place to not display the same content multiple times by default.
There are at least 4 different ways to display translatable nodes (or any content) in views.
1. Display all translations even if that means nodes are displayed multiple times. (which is what we have now)
2. Display all nodes in the current content language or best available fallback)
3. Display all nodes that are translated into the current content language, without fallbacks. (by adding a filter for "current content language"
4. Display all translations for a specific language that might be the current content language or not. (by adding a filter for language X)
Before this patch, only option 2 and 3 were possible, because no matter what language you actually selected, entity rendering in views then always displayed in the current content language or best fallback. Now, you can configure views to work with all those options.
The fact that we right now do option 1. is IMHO not a deliberate decision, it's also just a side affect. The reason is that we filter on the promoted flag, this is now a "possibly translatable field", which means it's stored in a separate table for each available translation. So views adds a join to that table, and because we don't have any further conditions, we get a SQL result for every translation.
Now, we just need to decide what the default should be for core in the mentioned follow-up issue, 2 (by making the query distinct, so that each nid is only returned once) or 3 (by adding a condition on the current language).
Hope that helps :)
Comment #168
Gábor HojtsyYay, thanks!