summaryrefslogtreecommitdiff
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
parent2f9fd67579a7d9db2853839dd6588d992a03fa69 (diff)
downloadbrdo-0bc39fef86c22c3eacf3431751ea1b428c179f92.tar.gz
brdo-0bc39fef86c22c3eacf3431751ea1b428c179f92.tar.bz2
#499192 by yched: Fix display and forms for 'Fieldable terms' .
-rw-r--r--modules/taxonomy/taxonomy-term.tpl.php51
-rw-r--r--modules/taxonomy/taxonomy.admin.inc5
-rw-r--r--modules/taxonomy/taxonomy.module111
-rw-r--r--modules/taxonomy/taxonomy.pages.inc13
4 files changed, 170 insertions, 10 deletions
diff --git a/modules/taxonomy/taxonomy-term.tpl.php b/modules/taxonomy/taxonomy-term.tpl.php
new file mode 100644
index 000000000..f48452c29
--- /dev/null
+++ b/modules/taxonomy/taxonomy-term.tpl.php
@@ -0,0 +1,51 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Default theme implementation to display a term.
+ *
+ * Available variables:
+ * - $name: the (sanitized) name of the term.
+ * - $content: An array of items for the content of the term (fields and
+ * description). Use render($content) to print them all, or print a subset
+ * such as render($content['field_example']). Use
+ * hide($content['field_example']) to temporarily suppress the printing of a
+ * given element.
+ * - $term_url: Direct url of the current term.
+ * - $classes: String of classes that can be used to style contextually through
+ * CSS. It can be manipulated through the variable $classes_array from
+ * preprocess functions. The default values can be one or more of the following:
+ * - taxonomy-term: The current template type, i.e., "theming hook".
+ * - vocabulary-[vocabulary-name]: The vocabulary to which the term belongs to.
+ * For example, if the term is a "Tag" it would result in "vocabulary-tag".
+ *
+ * Other variables:
+ * - $term: Full term object. Contains data that may not be safe.
+ * - $view_mode: View mode, e.g. 'full', 'teaser'...
+ * - $page: Flag for the full page state.
+ * - $classes_array: Array of html class attribute values. It is flattened
+ * into a string within the variable $classes.
+ * - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
+ * teaser listings.
+ * - $id: Position of the term. Increments each time it's output.
+ * - $is_front: Flags true when presented in the front page.
+ * - $logged_in: Flags true when the current user is a logged-in member.
+ * - $is_admin: Flags true when the current user is an administrator.
+ *
+ * @see template_preprocess()
+ * @see template_preprocess_taxonomy_term()
+ * @see template_process()
+ */
+?>
+<div id="taxonomy-term-<?php print $term->tid; ?>" class="<?php print $classes; ?> clearfix">
+
+ <?php if (!$page): ?>
+ <h2><a href="<?php print $term_url; ?>"><?php print $term_name; ?></a></h2>
+ <?php endif; ?>
+
+ <div class="content">
+ <?php print render($content); ?>
+ </div>
+
+</div>
diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc
index 98cdf2fc8..954a062f0 100644
--- a/modules/taxonomy/taxonomy.admin.inc
+++ b/modules/taxonomy/taxonomy.admin.inc
@@ -643,12 +643,15 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
'#title' => t('Name'),
'#default_value' => $edit['name'],
'#maxlength' => 255,
- '#required' => TRUE);
+ '#required' => TRUE,
+ '#weight' => -5,
+ );
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#text_format' => $edit['format'],
+ '#weight' => 0,
);
$form['vocabulary_machine_name'] = array(
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..
*/
diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc
index 0d731ca94..0bb19d76f 100644
--- a/modules/taxonomy/taxonomy.pages.inc
+++ b/modules/taxonomy/taxonomy.pages.inc
@@ -28,18 +28,13 @@ function taxonomy_term_page($term) {
$breadcrumb = array_reverse($breadcrumb);
drupal_set_breadcrumb($breadcrumb);
drupal_add_feed(url('taxonomy/term/' . $term->tid . '/feed'), 'RSS - ' . $term->name);
- drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css');
- field_attach_prepare_view('taxonomy_term', array($term->tid => $term), 'full');
- entity_prepare_view('taxonomy_term', array($term->tid => $term));
- $build = array();
- $build += field_attach_view('taxonomy_term', $term);
- $build['term_description'] = array(
- '#markup' => check_markup($term->description, $term->format, '', TRUE),
- '#weight' => -1,
- '#prefix' => '<div class="taxonomy-term-description">',
+ $build['term_heading'] = array(
+ '#prefix' => '<div class="term-listing-heading">',
'#suffix' => '</div>',
+ 'term' => taxonomy_term_view($term, 'full'),
);
+
if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
$nodes = node_load_multiple($nids);
$build += node_view_multiple($nodes);