Problem/Motivation
From the original bug report:
I have a view that lists nodes, filtered by contextual filter "Content: Has taxonomy term ID (with depth)".
In the view I override the view title in the contextual filter setting with "{{ arguments.term_node_tid_depth }}" token.
All the terms have translation, but I noticed that the title is always displayed in the default language.
Title should be displayed in current active translation.
Steps to reproduce
- Enable content_translation module
- add Spanish language
- Enable content translation to Spanish for taxonomy terms
- Create a taxonomy term (e.g. Butterfly) and translate it into Spanish (Mariposa)
- Change the taxonomy_term view to use the "Has taxonomy term ID (with depth)" argument, as well as the depth
- Ensure that "Replace title" is checked, and {{ arguments.term_node_tid_depth }} is used as the title replacement
- Go to the taxonomy term page in Spanish
- The English title will be shown instead of Spanish - this is the bug.
Proposed resolution
- In the views argument plugins, fetch the translation from context and try to get the label from translation.
Remaining tasks
Needs review
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#100 | 2765297-nr-bot.txt | 90 bytes | needs-review-queue-bot |
#92 | 2765297-nr-bot.txt | 3.54 KB | needs-review-queue-bot |
Issue fork drupal-2765297
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
heikki CreditAttribution: heikki at Avoltus Oy commentedComment #3
markdorison@heikki Can you provide more detail on the view you are describing or even provide an export of an example view so we might reproduce the issue you are describing?
Comment #6
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedRerolled the patch.
Comment #8
dnotes CreditAttribution: dnotes commentedThis works, and it looks like the proper solution (though check with views maintainers). Steps to reproduce, tested on Simplytest.me:
I'll attach the exported view config.
Comment #9
xjmThanks @dnotes, those steps to reproduce help. Adding them to the issue summary with screenshots of the before-and-after would be helpful.
Removing credit for @Munavijayalakshmi as the reroll was not needed there.
If this Views plugin needs the entity manager, it should have it inject. It might even already have it.
Finally, since this issue describes a bug, we need an automated regression test for the bug, that can be attached with by itself and show a fail on testing, followed by the whole patch which should pass.
Thanks everyone!
Comment #10
googletorp CreditAttribution: googletorp as a volunteer and at Reveal IT commentedI rewrote the patch using dependency injection as requested in #9.
Also I used entity.reposity instead of entity.manager since the entity.manager has been deprecated.
We still need to do tests etc for this.
Comment #11
dnotes CreditAttribution: dnotes commentedAdded steps to reproduce and screenshots to the description. This is with the patches from 2 and 6.
I'm a little confused that in order to fix this one-line bug, we are also updating the entire argument to use dependency injection and newer services. Shouldn't that be a separate issue applied to all the taxonomy term arguments at the same time? After all, those same changes are needed for all of the taxonomy term arguments, not just this one. If we update this because of a separate bug, then the code for the arguments get out of sync with each other and it just becomes a bigger mess than it is now.
Writing tests that incorporate changes to a view is beyond my capability.
Comment #12
sylus CreditAttribution: sylus commentedI have also updated the taxonomy.tokens.inc with roughly the same fix as the following also wasn't working with Taxonomy:
Comment #13
sylus CreditAttribution: sylus commentedHere is a patch just with my tokens fixes.
Comment #14
sylus CreditAttribution: sylus commentedAnother patch with some other corrections I needed to apply to Core 8.4.3. Will post an updated patch against dev soon.
Comment #15
sylus CreditAttribution: sylus commentedComment #16
sylus CreditAttribution: sylus commentedOkay this is incorporates the fixes from #2765297-10: Return translated term name on views "Content: Has taxonomy term ID (with depth)" as well as fixes for tokens + regular Taxonomy using
{{ arguments.tid }}
Comment #19
alduya CreditAttribution: alduya at 2DotsTwice bvba commentedThe same problem exists for the Nid / Content: ID filter.
I created a different issue for that: https://www.drupal.org/project/drupal/issues/2952252
Comment #20
AnybodyDid you check special character behaviour for term names? We should ensure to be not double-escaped. For example & => not becoming => & in view title.
Comment #21
robertom CreditAttribution: robertom at bmeme commentedHi, sorry for my bad english.
With this patch applied, I have a side effect on term alias.
I have a pathauto pattern set as "[term:parents]/[term:name]" for a vocabulary, when I save a term of this vocabulary, the alias generated for all languages of the term substitute the [term:name] token with the last translation saved instead of use the translated name.
Comment #22
kriboogh CreditAttribution: kriboogh at Calibrate commentedThe problem is the patch in taxonomy.tokens.inc
This causes the term to be returned to be in the current active language if none was given to getTranslationFromContext.
Pathauto hands over the language as an option, so to fix it, it should be:
BTW, this also causes problems in bulk pathauto generation with patterns having term:name tokens. These are all generated in the current active language. If for example you run pathauto bulk while using the admin pages in french, all aliases will have the french translation, even if your pattern is set for entities in an other language.
Comment #23
kriboogh CreditAttribution: kriboogh at Calibrate commentedHere's a patch for that....
Comment #24
AnybodyManual code review looks good so far from a logical perspective. Now we need some people to test and confirm.
Comment #26
willeaton CreditAttribution: willeaton commentedI confirm that the patch in #23 works in D8.6.1
Comment #27
googletorp CreditAttribution: googletorp as a volunteer and at Reveal IT commentedThanks for the test, per #24 and #26 I think we are good to go unless some one can spot any issues here.
Comment #28
catchThis could use some automated test coverage.
Comment #29
Viktor999 CreditAttribution: Viktor999 commentedI tried the patch in #23 in D8.6.4 and 8.6.5, but it does not work for me.
Comment #30
Berdirlets update this and others to use entity_type.manager instead when we touch the line anyway.
this should also use the entity repository service
Comment #31
daxgrapol CreditAttribution: daxgrapol commentedI have tested patch #23 on Drupal 8.6.5 and it works only if using "Content: Has taxonomy term ID (with depth)" as contextual filter.
In my case I have to use a Relationship with Term and then use it in the contextual filter "Taxonomy term: name" (I take the Term name in the URL and I override the title with {{ arguments.name }}, no other method works for me). In this case, patch dosn't work.
Comment #32
ducktape CreditAttribution: ducktape at District09 commentedWorks for me, tested on 8.7.2. Updated patch with remarks from @Berdir.
@daxgrapol I haven't tried reconstructing your case, but it looks to me you get your title straight from the path, so I think the translated name should be in there already.
Comment #33
ducktape CreditAttribution: ducktape at District09 commentedComment #34
mpp CreditAttribution: mpp at AmeXio for District09 commentedNitpick: we should always keep the same order between "EntityRepositoryInterface" & "EntityStorageInterface".
Since we added the EntityStorageInterface last we can put $entityRepository after $termStorage.
Same remark.
Same remark.
Same remark.
@berdir, should we test this against 8.8 or 8.7?
Comment #35
ducktape CreditAttribution: ducktape at District09 commentedComment #36
ducktape CreditAttribution: ducktape at District09 commentedUpdated patch with remarks from @mpp
Comment #37
mpp CreditAttribution: mpp at AmeXio for District09 commentedReviewed and tested.
Comment #38
AnybodyRe-Confirming RTBC by manual code review and additional manual testing. Happy to see this committed soon :)
Thank you all!
Comment #39
LendudeAs @xjm pointed out in #9, this still needs automated test coverage.
Comment #40
borisson_Should be FQN.
^
This change is unrelated.
Comment #41
mpp CreditAttribution: mpp at AmeXio for District09 commented@borisson_, see #30 by @berdir.
Comment #42
BerdirThis needs to go into 8.8 first, where it won't apply because these entity manager related changes already happened there.
Comment #43
borisson_@mpp, this should only happen when we update the line anyway, there is no other change in that line so I don't think that makes it allowed.
Comment #44
mpp CreditAttribution: mpp at AmeXio for District09 commentedThanks for the feedback @berdir, @borisson_.
off-topic: The same problem seems to occur for search_api view arguments (in Drupal\search_api\Plugin\views\argument\SearchApiTerm), see https://www.drupal.org/project/search_api/issues/3064479
Comment #45
ducktape CreditAttribution: ducktape at District09 commentedRerolled against 8.8.
Comment #46
ducktape CreditAttribution: ducktape at District09 commentedAnd added FQN as @borisson_ said in #40.
Comment #49
mdupontEDIT: commented on the wrong issue
Comment #50
AnybodyI just ran into the problem and can confirm this problem still exists. Replacement patterns from contextual filters are not usable on multilang sites and return unexpected results. Due to this I'll set the priority to Major. There is no workaround available.
Comment #51
AnybodyI can confirm patch #46 fixes the problems for us in a Drupal 8.9.2 installation without any side-effects experienced.
What's still missing since #9 & #39 is automated test coverage and there's still a TODO in the patch!
Comment #52
joseph.olstadpatch 46 needs a reroll for 9.1.x
patch 46 applies cleanly to 9.0.x
patch 46 applies cleanly to 8.9.x
Comment #53
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedComment #54
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedI have re-roll the patch for 9.1.x
Comment #56
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedComment #58
sir_squall CreditAttribution: sir_squall commentedI tried the patch #46 taxonomy_translation_2765297_0.patch in D9.0.7 and everything is working well
Comment #59
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedAdding a few test cases to validate the scenarios.
Approach:
Pretty much same as mentioned in steps to reproduce section.
Except I've created view with different URL, so it doesn't have issues with default taxonomy terms path.
Comment #60
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedFixed CS issues.
Comment #62
joseph.olstadoh wow thanks @anmolgoyal74, I need this patch ! :)
Rerolled for D8.9.x
(I have a project that needs this)
Comment #63
joseph.olstadOk here's a patch that rolls fine with D8.9.x, D9.0.x, D9.1.x and D9.2.x
See interdiff and new patch
Comment #65
joseph.olstadContrary to what the testbot says, patch 63 applies cleanly to D8.9.x, D9.0.x, D9.1.x, D9.2.x
Comment #66
Fernly CreditAttribution: Fernly at Dropsolid for District09 commented#63 works fine in 9.1.x. Thank you.
Comment #68
robertoperuzzoThank you joseph.olstad your patch #63 works on D9.1.9.
Comment #69
AnybodyFinally, confirming RTBC for #63, thank you very, very much @joseph.olstad and the others. Works on Drupal 9.2 and 9.3!
#63 contains tests, is that enough or are there any concerns to add further tests? Otherwise I'd suggest to remove that tag and set this RTBC?
Comment #71
alexverb CreditAttribution: alexverb as a volunteer and commentedPatch works properly. Removing testing tag and setting RTBC.
Comment #72
LendudeLooks great and it's fantastic to see the test coverage, but still needs a little work I'm afraid.
Unfortunately we can't change these constructors without some BC layer (default it to NULL and inject from \Drupal and add a deprecation message that you now need to inject this, should be some examples in core). Anything extending these classes could break otherwise.
Edit: Or don't we do this dance for plugins?
Also, it seems we are changing 2 plugins, but only have test coverage for 1, so we need to extend the coverage to both plugins that get changed.
Comment #73
yogeshmpawarReroll against 9.4.x latest branch & added reroll diff for reviewers.
Comment #74
yogeshmpawarKeeping it in NW for #72
Comment #79
joseph.olstadWhile we do have test coverage, Lendude mentioned that one additional test is required.
Comment #80
joseph.olstadSee MR 6625
Comment #81
joseph.olstadPretty sure to fix the tests this yml file needs to be corrected/updated in a vanilla install of D11 or D10.2 . (With the patch applied of course)
core/modules/taxonomy/tests/modules/taxonomy_test_views/test_views/views.view.taxonomy_translated_term_name_test.yml
I'm hoping someone can carry the baton from here.
Comment #82
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented- Tests are green now.
There was one deprecated config change in view. Sorted that out.
- Updated issue summary and moving it to Needs Review
- Removed Needs test tag since it is not required anymore.
Comment #83
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedComment #84
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedWorking on the test coverage for the second plugin.
Comment #85
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented- Added the test case for the another ViewsArgument plugin.
- Tests are passing on local as well as CI
- Unusual failure form nightwatch tests, triggered the job again.
Comment #86
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #87
joseph.olstadComment #88
joseph.olstad@mohit_rocks , thanks for the excellent work on the tests! Marking this as ready.
Comment #89
alexpottHiding all the patch files since this issue is using an MR.
Comment #90
alexpottAdded some review comments to the MR. This is a nice - we need to take care of classes that extend the core classes and I think there is a slightly better way of doing things.
Comment #91
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedAddressed the PR feedback.
I think https://git.drupalcode.org/project/drupal/-/merge_requests/6625#note_276326 would need some verification while doing review.
I'm somewhat confused about that.
Other point seems clear.
Comment #92
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #93
joseph.olstadComment #94
joseph.olstadok, it's clean now.
RTBC
Comment #95
alexpottI've made a mistake here. DeprecatedServicePropertyTrait doesn't support entity storages. I'll fix the MR.
Comment #96
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented@alexpott do we need a change record for this one?
Comment #97
alexpott@mohit_aghera - yes we should have something small and simple... and the @see should point to it and not this issue. Great catch.
Can you add one, fix the MR and then set this back to RTBC?
Comment #98
alexpottHere's an example MR doing the same thing... https://www.drupal.org/node/3397213
Comment #99
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedChange record created. Back to RTBC
Comment #100
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #102
adwivedi008 CreditAttribution: adwivedi008 at OpenSense Labs for DrupalFit commentedResolved the coding standard issue at last MR due to which the pipeline was failing and setting back the status to RTBC from Needs works
Please review and suggest if any other changes are required.
Comment #103
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented@adwivedi008, can you please be sure that we need to fix the issues?
Reason is comment in #100is saying that patch is no longer applied to the core.
In this case, you need to merge latest 11.x to the branch.
I tried that and it seemed to be working fine.
Comment #104
alexpott@adwivedi008 your fixes are not fixes - core's coding standards are checked on every commit to an MR - the pipeline was green after #99 but your changes broke the pipeline. The "drupal" coding standard as detailed by coder is not the the core coding standard. Core is working towards it but we should never make out of scope changes to satisfy it and we should adhere to the coding standard set in core/phpcs.xml.dist as the "drupal" coding standard from coder actually needs fixing. I have reverted your changes.
Comment #105
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedUpdated branch with latest 11.x head since test case failures were related to 11.x HEAD only.
Keeping it to RTBC, will check if there are any failures.
Comment #106
alexpottCommitted and pushed 18c45f5f23 to 11.x and 462d3ac638 to 10.3.x. Thanks!
It'd be good to finish up #2640994: Label token replacement for views entity reference arguments not working and put a more generic fix in place.
Comment #111
catchThis caused the gitlab performance test jobs to fail over the weekend, with:
Since
ViewsArgumentDeprecationTest
appears to be mainly (only?) testing the constructor deprecation, I don't think that was necessary to add in the first place and we could just remove the test, but I didn't review to see if there was a better reason for adding it.Comment #112
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented@catch
I added that initially and my intention was to validate two things.
Happy to remove the test case entirely or just expect deprecation only.
Let me know your thoughts.
Comment #113
alexpott@catch @mohit_aghera this test only caused that because it unnecessarily used the trait. Remove the use and this will pass fine as we literally have hundreds of other deprecation tests doing the same thing.
I think leaving a test in in this case is okay because of the slightly more complicated dance of changing a parameter instead of just adding or removing a parameter.
Given this is just removing usage of a trait setting back to rtbc.
Comment #114
catchMakes sense to me - I can re-commit this a bit later but also think it'd be fine for @alexpott to commit the updated MR here since it's a tiny change.
Comment #115
alexpottCommitted and pushed 1bcc7f34e6 to 11.x and 46564ee733 to 10.3.x. Thanks!
Second time lucky.