summaryrefslogtreecommitdiff
path: root/modules/taxonomy/taxonomy.module
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-10 06:28:10 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-02-10 06:28:10 +0000
commit0bc39fef86c22c3eacf3431751ea1b428c179f92 (patch)
treeeaf685f5dff859b684be13bc1ec758ed093e25a8 /modules/taxonomy/taxonomy.module
parent2f9fd67579a7d9db2853839dd6588d992a03fa69 (diff)
downloadbrdo-0bc39fef86c22c3eacf3431751ea1b428c179f92.tar.gz
brdo-0bc39fef86c22c3eacf3431751ea1b428c179f92.tar.bz2
#499192 by yched: Fix display and forms for 'Fieldable terms' .
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r--modules/taxonomy/taxonomy.module111
1 files changed, 111 insertions, 0 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 7c3b2e69b..13578be04 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -137,6 +137,30 @@ function taxonomy_term_path($term) {
}
/**
+ * Implements hook_field_extra_fields().
+ */
+function taxonomy_field_extra_fields() {
+ $return = array();
+
+ foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) {
+ $return['taxonomy_term'][$machine_name] = array(
+ 'name' => array(
+ 'label' => t('Name'),
+ 'description' => t('Term name textfield'),
+ 'weight' => -5,
+ ),
+ 'description' => array(
+ 'label' => t('Description'),
+ 'description' => t('Term description textarea'),
+ 'weight' => 0,
+ )
+ );
+ }
+
+ return $return;
+}
+
+/**
* Return nodes attached to a term across all field instances.
*
* This function requires taxonomy module to be maintaining its own tables,
@@ -201,6 +225,10 @@ function taxonomy_theme() {
'taxonomy_overview_terms' => array(
'render element' => 'form',
),
+ 'taxonomy_term' => array(
+ 'render element' => 'elements',
+ 'template' => 'taxonomy-term',
+ ),
);
}
@@ -565,6 +593,89 @@ function taxonomy_term_delete($tid) {
return SAVED_DELETED;
}
+
+/**
+ * Generate an array for rendering the given term.
+ *
+ * @param $term
+ * A term object.
+ * @param $view_mode
+ * View mode, e.g. 'full', 'teaser'...
+ *
+ * @return
+ * An array as expected by drupal_render().
+ */
+function taxonomy_term_view($term, $view_mode = 'full') {
+ field_attach_prepare_view('taxonomy_term', array($term->tid => $term), $view_mode);
+ entity_prepare_view('taxonomy_term', array($term->tid => $term));
+
+ $build = array(
+ '#theme' => 'taxonomy_term',
+ '#term' => $term,
+ '#view_mode' => $view_mode,
+ );
+
+ $build += field_attach_view('taxonomy_term', $term, $view_mode);
+
+ $build['description'] = array(
+ '#markup' => check_markup($term->description, $term->format, '', TRUE),
+ '#weight' => 0,
+ '#prefix' => '<div class="taxonomy-term-description">',
+ '#suffix' => '</div>',
+ );
+
+ $build['#attached']['css'][] = drupal_get_path('module', 'taxonomy') . '/taxonomy.css';
+
+ return $build;
+}
+
+/**
+ * Process variables for taxonomy-term.tpl.php.
+ */
+function template_preprocess_taxonomy_term(&$variables) {
+ $variables['view_mode'] = $variables['elements']['#view_mode'];
+ $variables['term'] = $variables['elements']['#term'];
+ $term = $variables['term'];
+
+ $variables['term_url'] = url('taxonomy/term/' . $term->tid);
+ $variables['term_name'] = check_plain($term->name);
+ $variables['page'] = taxonomy_term_is_page($term);
+
+ // Flatten the term object's member fields.
+ $variables = array_merge((array)$term, $variables);
+
+ // Helpful $content variable for templates.
+ foreach (element_children($variables['elements']) as $key) {
+ $variables['content'][$key] = $variables['elements'][$key];
+ }
+
+ // field_attach_preprocess() overwrites the $[field_name] variables with the
+ // values of the field in the language that was selected for display, instead
+ // of the raw values in $term->[field_name], which contain all values in all
+ // languages.
+ field_attach_preprocess('taxonomy_term', $term, $variables['content'], $variables);
+
+ $vocabulary_name_css = str_replace('_', '-', $term->vocabulary_machine_name);
+
+ // Gather classes.
+ $variables['classes_array'][] = 'vocabulary-' . $vocabulary_name_css;
+
+ // Clean up name so there are no underscores.
+ $variables['theme_hook_suggestions'][] = 'taxonomy-term__' . $vocabulary_name_css;
+ $variables['theme_hook_suggestions'][] = 'taxonomy-term__' . $term->tid;
+}
+
+/**
+ * Returns whether the current page is the page of the passed in term.
+ *
+ * @param $term
+ * A term object.
+ */
+function taxonomy_term_is_page($term) {
+ $page_term = menu_get_object('taxonomy_term', 2);
+ return (!empty($page_term) ? $page_term->tid == $term->tid : FALSE);
+}
+
/**
* Clear all static cache variables for terms..
*/