Instead of directly displaying taxonomy terms with $term->name, Views should use entity_label('taxonomy_term', $term).

i18n_taxonomy.module for example automatically integrates with that to show the translated term title, if available.

This should make i18nviews's life easier and could probably deprecate a number of taxonomy handlers which do nothing else but display the term title in the correct language. And it should also make it much easier for users. Had to dive really deep into the views code to understand that I also need the i18n term argument validation handler because that one does inject the validated title ;)

Needs more testing, but seemed to work for me. Most $term's are actually not loaded with taxonomy_term_load() but use custom queries, that's a bit.. unfortunate but works in 7.x.

Consider this as a proof of concept :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

FileSize
3.74 KB

Better patch, still had a $term->name in there.

dawehner’s picture

Issue tags: +Needs manual testing

Thanks for working on it!

Needs more testing, but seemed to work for me. Most $term's are actually not loaded with taxonomy_term_load() but use custom queries, that's a bit.. unfortunate but works in 7.x.

I don't want to change these things in d7 unless we have tests for it, but in general your changes looks fine. For d8 we either have fixed it already or there are issues for that.

dawehner’s picture

+++ b/modules/taxonomy/views_handler_field_term_node_tid.incundefined
@@ -112,7 +112,7 @@ class views_handler_field_term_node_tid extends views_handler_field_prerender_li
+        $this->items[$term->node_nid][$term->tid]['name'] = check_plain(entity_label('taxonomy_term', $term));

+++ b/modules/taxonomy/views_plugin_argument_validate_taxonomy_term.incundefined
@@ -103,7 +103,7 @@ class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument
+        $this->argument->validated_title = check_plain(entity_label('taxonomy_term', $term));

@@ -152,7 +152,7 @@ class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument
+            $titles[] = $validated_cache[$term->tid] = check_plain(entity_label('taxonomy_term', $term));

@@ -185,7 +185,7 @@ class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument
+          $this->argument->validated_title = check_plain(entity_label('taxonomy_term', $term));

Should we ever call entity_label on an entity which is not loaded totally?

Berdir’s picture

Re-roll, looks like one file was already fixed.

One case remaining where we don't load the entity. Not sure if we should load or not.

Chris Matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 5 year old patch in #4 does not apply to the latest views 7.x-3.x-dev and if still applicable needs reroll.

Checking patch modules/taxonomy/views_handler_argument_taxonomy.inc...
error: while searching for:
    if ($this->argument) {
      $term = taxonomy_term_load($this->argument);
      if (!empty($term)) {
        return check_plain($term->name);
      }
    }
    // TODO review text

error: patch failed: modules/taxonomy/views_handler_argument_taxonomy.inc:20
error: modules/taxonomy/views_handler_argument_taxonomy.inc: patch does not apply
Checking patch modules/taxonomy/views_handler_argument_term_node_tid_depth.inc...
error: while searching for:
  function title() {
    $term = taxonomy_term_load($this->argument);
    if (!empty($term)) {
      return check_plain($term->name);
    }
    // TODO review text
    return t('No name');

error: patch failed: modules/taxonomy/views_handler_argument_term_node_tid_depth.inc:137
error: modules/taxonomy/views_handler_argument_term_node_tid_depth.inc: patch does not apply
Checking patch modules/taxonomy/views_handler_field_term_node_tid.inc...
Hunk #1 succeeded at 122 (offset 10 lines).
Andrew Answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
2.21 KB

Patch rerolled.

AlfTheCat’s picture

Status: Needs review » Needs work

After applying the patch, I get a fatal error and the taxonomy page breaks. I tried the latest views dev release and the latest stable release, both with the same result.

The error in the log:
EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 8003 of /var/aegir/platforms/[xxxx]/includes/common.inc).