Problem/Motivation

When using a taxonomy term views argument, the label used in the title override is not translated.

This has also been logged in core on the term views argument plugins there.

Proposed resolution

Use Entity Repository to load the translated label.

Comments

ducktape created an issue. See original summary.

ducktape’s picture

Status: Active » Needs review
StatusFileSize
new2.06 KB

Attached a patch based on the work done in the related issue in core.

mpp’s picture

  1. +++ b/src/Plugin/views/argument/SearchApiTerm.php
    @@ -19,6 +21,47 @@ use Drupal\taxonomy\Entity\Term;
    +    /** @var static $plugin */
    

    We can remove this.

  2. +++ b/src/Plugin/views/argument/SearchApiTerm.php
    @@ -19,6 +21,47 @@ use Drupal\taxonomy\Entity\Term;
    +   * Retrieves the entity repository.
    

    Sets

  3. +++ b/src/Plugin/views/argument/SearchApiTerm.php
    @@ -19,6 +21,47 @@ use Drupal\taxonomy\Entity\Term;
    +   * Sets the entity repository.
    

    Retrieves

Swap the return values in the dochead of the get/setter and add a return $this in the setter.

Tests are broken, we'll have to add the entity repository in the tests.

Would have been useful if we had the EntityRepositoryTrait in Drupal 8.

Note: There's a Term::load() statement in SearchApiTerm::title(). Opened a follow up issue to fix this.

Status: Needs review » Needs work

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

ducktape’s picture

Status: Needs work » Needs review
StatusFileSize
new3.16 KB

Updated the function docblocks and fixed the tests to use the entity repository.

mpp’s picture

Status: Needs review » Reviewed & tested by the community

Tests are green, the patch looks good and was tested on our project.

Note: no specific test to check that we get the translated language was added, I would assume that getTranslationFromContext is fully covered so it would not add much value to test getTranslationFromContext() in search_api.

borisson_’s picture

Note: no specific test to check that we get the translated language was added, I would assume that getTranslationFromContext is fully covered so it would not add much value to test getTranslationFromContext() in search_api.

I agree with this.

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.9 KB
new2.11 KB

Thanks a lot for reporting this here and already providing a patch!
However, while it worked, the patch did have some problems which I have addressed in the attached revision. Please confirm this still looks and works OK for you and I can commit.

In my opinion, a regression test would have been nice, too, to make sure this doesn’t break again in the future, but if even Joris is OK without it, then I won’t insist.

trebormc’s picture

#8 works fine for me. Thanks

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Looks great

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great to hear, thanks for testing/reviewing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.