From 43c0b472bca7eba4e0890c96b3977e1e5ab095ad Mon Sep 17 00:00:00 2001
From: Florian Weber <florian@webflo.org>
Date: Fri, 15 Jun 2012 19:31:04 +0200
Subject: [PATCH] Issue #1616972: Replace $term->name with $term->label().

---
 core/modules/field/modules/options/options.api.php |    4 +--
 core/modules/forum/forum-list.tpl.php              |    2 +-
 core/modules/forum/forum.admin.inc                 |   10 ++++----
 core/modules/forum/forum.module                    |   12 ++++-----
 .../lib/Drupal/rdf/Tests/MappingDefinitionTest.php |    6 ++---
 core/modules/rdf/rdf.module                        |    2 +-
 .../lib/Drupal/taxonomy/TermStorageController.php  |    2 +-
 .../lib/Drupal/taxonomy/Tests/TermFieldTest.php    |    2 +-
 core/modules/taxonomy/taxonomy.admin.inc           |   26 ++++++++++----------
 core/modules/taxonomy/taxonomy.module              |   22 ++++++++---------
 core/modules/taxonomy/taxonomy.pages.inc           |    8 +++---
 11 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/core/modules/field/modules/options/options.api.php b/core/modules/field/modules/options/options.api.php
index ce2ec62..d622137 100644
--- a/core/modules/field/modules/options/options.api.php
+++ b/core/modules/field/modules/options/options.api.php
@@ -61,10 +61,10 @@ function hook_options_list($field, $instance, $entity_type, $entity) {
   // on properties of the field. Example from taxonomy.module:
   $options = array();
   foreach ($field['settings']['allowed_values'] as $tree) {
-    $terms = taxonomy_get_tree($tree['vid'], $tree['parent']);
+    $terms = taxonomy_get_tree($tree['vid'], $tree['parent'], NULL, TRUE);
     if ($terms) {
       foreach ($terms as $term) {
-        $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
+        $options[$term->tid] = str_repeat('-', $term->depth) . $term->label();
       }
     }
   }
diff --git a/core/modules/forum/forum-list.tpl.php b/core/modules/forum/forum-list.tpl.php
index 01c74a3..b169493 100644
--- a/core/modules/forum/forum-list.tpl.php
+++ b/core/modules/forum/forum-list.tpl.php
@@ -54,7 +54,7 @@
           <div class="icon forum-status-<?php print $forum->icon_class; ?>" title="<?php print $forum->icon_title; ?>">
             <span class="element-invisible"><?php print $forum->icon_title; ?></span>
           </div>
-          <div class="name"><a href="<?php print $forum->link; ?>"><?php print $forum->name; ?></a></div>
+          <div class="name"><a href="<?php print $forum->link; ?>"><?php print $forum->label(); ?></a></div>
           <?php if ($forum->description): ?>
             <div class="description"><?php print $forum->description; ?></div>
           <?php endif; ?>
diff --git a/core/modules/forum/forum.admin.inc b/core/modules/forum/forum.admin.inc
index dea573c..b26756f 100644
--- a/core/modules/forum/forum.admin.inc
+++ b/core/modules/forum/forum.admin.inc
@@ -211,9 +211,9 @@ function forum_confirm_delete($form, &$form_state, $tid) {
   $term = taxonomy_term_load($tid);
 
   $form['tid'] = array('#type' => 'value', '#value' => $tid);
-  $form['name'] = array('#type' => 'value', '#value' => $term->name);
+  $form['name'] = array('#type' => 'value', '#value' => $term->label());
 
-  return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit <a href="@content">content administration</a> first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete'), t('Cancel'));
+  return confirm_form($form, t('Are you sure you want to delete the forum %label?', array('%label' => $term->label())), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit <a href="@content">content administration</a> first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete'), t('Cancel'));
 }
 
 /**
@@ -327,7 +327,7 @@ function _forum_parent_select($tid, $title, $child_type) {
   }
 
   $vid = variable_get('forum_nav_vocabulary', '');
-  $children = taxonomy_get_tree($vid, $tid);
+  $children = taxonomy_get_tree($vid, $tid, NULL, TRUE);
 
   // A term can't be the child of itself, nor of its children.
   foreach ($children as $child) {
@@ -335,12 +335,12 @@ function _forum_parent_select($tid, $title, $child_type) {
   }
   $exclude[] = $tid;
 
-  $tree = taxonomy_get_tree($vid);
+  $tree = taxonomy_get_tree($vid, 0, NULL, TRUE);
   $options[0] = '<' . t('root') . '>';
   if ($tree) {
     foreach ($tree as $term) {
       if (!in_array($term->tid, $exclude)) {
-        $options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->name;
+        $options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->label();
       }
     }
   }
diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module
index ca9bf7e..85844f1 100644
--- a/core/modules/forum/forum.module
+++ b/core/modules/forum/forum.module
@@ -274,7 +274,7 @@ function forum_node_view(Node $node, $view_mode) {
       if ($parents = taxonomy_term_load_parents_all($node->forum_tid)) {
         $parents = array_reverse($parents);
         foreach ($parents as $parent) {
-          $breadcrumb[] = l($parent->name, 'forum/' . $parent->tid);
+          $breadcrumb[] = l($parent->label(), 'forum/' . $parent->tid);
         }
       }
       drupal_set_breadcrumb($breadcrumb);
@@ -313,7 +313,7 @@ function forum_node_validate(Node $node, $form) {
           ':vid' => $term->vid,
         ))->fetchField();
         if ($used && in_array($term->tid, $containers)) {
-          form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->name)));
+          form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->label())));
         }
       }
     }
@@ -793,7 +793,7 @@ function forum_forum_load($tid = NULL) {
 
   // Load the tree below.
   $forums = array();
-  $_forums = taxonomy_get_tree($vid, $tid);
+  $_forums = taxonomy_get_tree($vid, $tid, NULL, TRUE);
 
   if (count($_forums)) {
     $query = db_select('node', 'n');
@@ -1069,10 +1069,10 @@ function template_preprocess_forums(&$variables) {
     $variables['parents'] = array_reverse($variables['parents']);
     foreach ($variables['parents'] as $p) {
       if ($p->tid == $variables['tid']) {
-        $title = $p->name;
+        $title = $p->label();
       }
       else {
-        $breadcrumb[] = l($p->name, 'forum/' . $p->tid);
+        $breadcrumb[] = l($p->label(), 'forum/' . $p->tid);
       }
     }
   }
@@ -1140,7 +1140,7 @@ function template_preprocess_forum_list(&$variables) {
   foreach ($variables['forums'] as $id => $forum) {
     $variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : '';
     $variables['forums'][$id]->link = url("forum/$forum->tid");
-    $variables['forums'][$id]->name = check_plain($forum->name);
+    $variables['forums'][$id]->name = check_plain($forum->label());
     $variables['forums'][$id]->is_container = !empty($forum->container);
     $variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even';
     $row++;
diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/MappingDefinitionTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/MappingDefinitionTest.php
index 98a36d5..c9b10d6 100644
--- a/core/modules/rdf/lib/Drupal/rdf/Tests/MappingDefinitionTest.php
+++ b/core/modules/rdf/lib/Drupal/rdf/Tests/MappingDefinitionTest.php
@@ -138,10 +138,10 @@ class MappingDefinitionTest extends TaxonomyTestBase {
     // Views the term and checks that the RDFa markup is correct.
     $this->drupalGet('taxonomy/term/' . $term->tid);
     $term_url = url('taxonomy/term/' . $term->tid);
-    $term_name = $term->name;
-    $term_rdfa_meta = $this->xpath('//meta[@typeof="skos:Concept" and @about=:term-url and contains(@property, "rdfs:label") and contains(@property, "skos:prefLabel") and @content=:term-name]', array(
+    $term_label = $term->label();
+    $term_rdfa_meta = $this->xpath('//meta[@typeof="skos:Concept" and @about=:term-url and contains(@property, "rdfs:label") and contains(@property, "skos:prefLabel") and @content=:term-label]', array(
       ':term-url' => $term_url,
-      ':term-name' => $term_name,
+      ':term-label' => $term_label,
     ));
     $this->assertTrue(!empty($term_rdfa_meta), t('RDFa markup found on term page.'));
   }
diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module
index 43ee4ed..7bbe04c 100644
--- a/core/modules/rdf/rdf.module
+++ b/core/modules/rdf/rdf.module
@@ -745,7 +745,7 @@ function rdf_preprocess_taxonomy_term(&$variables) {
         'about' => url('taxonomy/term/' . $term->tid),
         'typeof' => $term->rdf_mapping['rdftype'],
         'property' => $term->rdf_mapping['name']['predicates'],
-        'content' => $term->name,
+        'content' => $term->label(),
       ),
     );
   drupal_add_html_head($term_label_meta, 'rdf_term_label');
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php
index 09b0d80..d1566b5 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermStorageController.php
@@ -70,7 +70,7 @@ class TermStorageController extends DatabaseStorageController {
     // Name matching is case insensitive, note that with some collations
     // LOWER() and drupal_strtolower() may return different results.
     foreach ($terms as $term) {
-      if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($term->name))) {
+      if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($term->label()))) {
         unset($terms[$term->tid]);
       }
     }
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
index 37661b9..6d5ea92 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php
@@ -119,7 +119,7 @@ class TermFieldTest extends TaxonomyTestBase {
     field_attach_prepare_view('test_entity', $entities, 'full');
     $entity->content = field_attach_view('test_entity', $entity, 'full');
     $this->content = drupal_render($entity->content);
-    $this->assertText($term->name, 'Term name is displayed.');
+    $this->assertText($term->label(), 'Term label is displayed.');
 
     // Delete the vocabulary and verify that the widget is gone.
     taxonomy_vocabulary_delete($this->vocabulary->vid);
diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc
index be020a6..86d8d45 100644
--- a/core/modules/taxonomy/taxonomy.admin.inc
+++ b/core/modules/taxonomy/taxonomy.admin.inc
@@ -281,7 +281,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) {
 
   $delta = 0;
   $term_deltas = array();
-  $tree = taxonomy_get_tree($vocabulary->vid);
+  $tree = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE);
   $term = current($tree);
   do {
     // In case this tree is completely empty.
@@ -372,7 +372,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) {
       unset($form[$key]['#term']['parents'], $term->parents);
     }
 
-    $form[$key]['view'] = array('#type' => 'link', '#title' => $term->name, '#href' => "taxonomy/term/$term->tid");
+    $form[$key]['view'] = array('#type' => 'link', '#title' => $term->label(), '#href' => "taxonomy/term/$term->tid");
     if ($vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
       $form['#parent_fields'] = TRUE;
       $form[$key]['tid'] = array(
@@ -692,7 +692,7 @@ function taxonomy_form_term($form, &$form_state, Term $term = NULL, Vocabulary $
   $form['name'] = array(
     '#type' => 'textfield',
     '#title' => t('Name'),
-    '#default_value' => $term->name,
+    '#default_value' => $term->label(),
     '#maxlength' => 255,
     '#required' => TRUE,
     '#weight' => -5,
@@ -734,14 +734,14 @@ function taxonomy_form_term($form, &$form_state, Term $term = NULL, Vocabulary $
     }
     $exclude[] = $term->tid;
 
-    $tree = taxonomy_get_tree($vocabulary->vid);
+    $tree = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE);
     $options = array('<' . t('root') . '>');
     if (empty($parent)) {
       $parent = array(0);
     }
     foreach ($tree as $item) {
       if (!in_array($item->tid, $exclude)) {
-        $options[$item->tid] = str_repeat('-', $item->depth) . $item->name;
+        $options[$item->tid] = str_repeat('-', $item->depth) . $item->label();
       }
     }
     $form['relations']['parent'] = array(
@@ -818,12 +818,12 @@ function taxonomy_form_term_submit($form, &$form_state) {
   $status = taxonomy_term_save($term);
   switch ($status) {
     case SAVED_NEW:
-      drupal_set_message(t('Created new term %term.', array('%term' => $term->name)));
-      watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
+      drupal_set_message(t('Created new term %term.', array('%term' => $term->label())));
+      watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
       break;
     case SAVED_UPDATED:
-      drupal_set_message(t('Updated term %term.', array('%term' => $term->name)));
-      watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
+      drupal_set_message(t('Updated term %term.', array('%term' => $term->label())));
+      watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->label()), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
       // Clear the page and block caches to avoid stale data.
       cache_invalidate(array('content' => TRUE));
       break;
@@ -861,7 +861,7 @@ function taxonomy_form_term_submit_build_taxonomy_term($form, &$form_state) {
   entity_form_submit_build_entity('taxonomy_term', $term, $form, $form_state);
 
   // Prevent leading and trailing spaces in term names.
-  $term->name = trim($term->name);
+  $term->name = trim($term->label());
 
   // Convert text_format field into values expected by taxonomy_term_save().
   $description = $form_state['values']['description'];
@@ -892,19 +892,19 @@ function taxonomy_form_term_delete_submit($form, &$form_state) {
  * @ingroup forms
  * @see taxonomy_term_confirm_delete_submit()
  */
-function taxonomy_term_confirm_delete($form, &$form_state, $term) {
+function taxonomy_term_confirm_delete($form, &$form_state, Term $term) {
   // Always provide entity id in the same form key as in the entity edit form.
   $form['tid'] = array('#type' => 'value', '#value' => $term->tid);
 
   $form['#term'] = $term;
   $form['#vocabulary'] = taxonomy_vocabulary_load($term->vid);;
   $form['type'] = array('#type' => 'value', '#value' => 'term');
-  $form['name'] = array('#type' => 'value', '#value' => $term->name);
+  $form['name'] = array('#type' => 'value', '#value' => $term->label());
   $form['vocabulary_machine_name'] = array('#type' => 'value', '#value' => $term->vocabulary_machine_name);
   $form['delete'] = array('#type' => 'value', '#value' => TRUE);
   return confirm_form($form,
     t('Are you sure you want to delete the term %title?',
-    array('%title' => $term->name)),
+    array('%title' => $term->label())),
     'admin/structure/taxonomy',
     t('Deleting a term will delete all its children if there are any. This action cannot be undone.'),
     t('Delete'),
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 6697a0a..f71eadc 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -627,7 +627,7 @@ function template_preprocess_taxonomy_term(&$variables) {
 
   $uri = entity_uri('taxonomy_term', $term);
   $variables['term_url']  = url($uri['path'], $uri['options']);
-  $variables['term_name'] = check_plain($term->name);
+  $variables['term_name'] = check_plain($term->label());
   $variables['page']      = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
 
   // Flatten the term object's member fields.
@@ -1051,13 +1051,13 @@ function taxonomy_implode_tags($tags, $vid = NULL) {
     // Extract terms belonging to the vocabulary in question.
     if (!isset($vid) || $tag->vid == $vid) {
       // Make sure we have a completed loaded taxonomy term.
-      if (isset($tag->name)) {
+      if ($tag instanceof EntityInterface && $label = $tag->label()) {
         // Commas and quotes in tag names are special cases, so encode 'em.
-        if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
-          $typed_tags[] = '"' . str_replace('"', '""', $tag->name) . '"';
+        if (strpos($label, ',') !== FALSE || strpos($label, '"') !== FALSE) {
+          $typed_tags[] = '"' . str_replace('"', '""', $label) . '"';
         }
         else {
-          $typed_tags[] = $tag->name;
+          $typed_tags[] = $label;
         }
       }
     }
@@ -1242,7 +1242,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
           $uri = entity_uri('taxonomy_term', $term);
           $element[$delta] = array(
             '#type' => 'link',
-            '#title' => $term->name,
+            '#title' => $term->label(),
             '#href' => $uri['path'],
             '#options' => $uri['options'],
           );
@@ -1252,7 +1252,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
 
     case 'taxonomy_term_reference_plain':
       foreach ($items as $delta => $item) {
-        $name = ($item['tid'] != 'autocreate' ? $item['taxonomy_term']->name : $item['name']);
+        $name = ($item['tid'] != 'autocreate' ? $item['taxonomy_term']->label() : $item['name']);
         $element[$delta] = array(
           '#markup' => check_plain($name),
         );
@@ -1263,7 +1263,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
       foreach ($items as $delta => $item) {
         $entity->rss_elements[] = array(
           'key' => 'category',
-          'value' => $item['tid'] != 'autocreate' ? $item['taxonomy_term']->name : $item['name'],
+          'value' => $item['tid'] != 'autocreate' ? $item['taxonomy_term']->label() : $item['name'],
           'attributes' => array(
             'domain' => $item['tid'] != 'autocreate' ? url('taxonomy/term/' . $item['tid'], array('absolute' => TRUE)) : '',
           ),
@@ -1297,9 +1297,9 @@ function taxonomy_allowed_values($field, $instance, $entity_type, $entity) {
   $options = array();
   foreach ($field['settings']['allowed_values'] as $tree) {
     if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
-      if ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'])) {
+      if ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], NULL, TRUE)) {
         foreach ($terms as $term) {
-          $options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
+          $options[$term->tid] = str_repeat('-', $term->depth) . $term->label();
         }
       }
     }
@@ -1367,7 +1367,7 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
  *   The term name to be used as the page title.
  */
 function taxonomy_term_title(Term $term) {
-  return $term->name;
+  return $term->label();
 }
 
 /**
diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc
index c84a6bd..74152c0 100644
--- a/core/modules/taxonomy/taxonomy.pages.inc
+++ b/core/modules/taxonomy/taxonomy.pages.inc
@@ -16,7 +16,7 @@ use Drupal\taxonomy\Vocabulary;
  */
 function taxonomy_term_page(Term $term) {
   // Assign the term name as the page title.
-  drupal_set_title($term->name);
+  drupal_set_title($term->label());
 
   // Build breadcrumb based on the hierarchy of the term.
   $current = (object) array(
@@ -27,12 +27,12 @@ function taxonomy_term_page(Term $term) {
   $breadcrumb = array();
   while ($parents = taxonomy_term_load_parents($current->tid)) {
     $current = array_shift($parents);
-    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
+    $breadcrumb[] = l($current->label(), 'taxonomy/term/' . $current->tid);
   }
   $breadcrumb[] = l(t('Home'), NULL);
   $breadcrumb = array_reverse($breadcrumb);
   drupal_set_breadcrumb($breadcrumb);
-  drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
+  drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->label());
 
   $build = array();
 
@@ -68,7 +68,7 @@ function taxonomy_term_page(Term $term) {
  */
 function taxonomy_term_feed(Term $term) {
   $channel['link'] = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE));
-  $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $term->name;
+  $channel['title'] = variable_get('site_name', 'Drupal') . ' - ' . $term->label();
   // Only display the description if we have a single term, to avoid clutter and confusion.
   // HTML will be removed from feed description.
   $channel['description'] = check_markup($term->description, $term->format, '', TRUE);
-- 
1.7.10.3

