Commit 0bc39fef authored by webchick's avatar webchick
Browse files

#499192 by yched: Fix display and forms for 'Fieldable terms' .

parent 2f9fd675
<?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>
......@@ -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(
......
......@@ -136,6 +136,30 @@ function taxonomy_term_path($term) {
return 'taxonomy/term/' . $term->tid;
}
/**
* 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.
*
......@@ -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..
*/
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment