- Apollo Astronaut Dr. Edgar Mitchell Talks About Life on Other Planets
- The Way We Work: Twitter del.icio.us Hack
- Video of Scalable Theming Session from Drupalcon Boston
- Google's Mapping User Experience; Where have you been?
- The Importance of Strategies, Operating Plans & Success Metrics for NGOs
- vi, Drupal Search, and Playa Del Carmen Retreat
- "Breadcrumb" Definition
- Support the Warrior, Not The War.
- Firefox Tip: Changing Default Browser URL Bar Behavior On Click
- DrupalCamp Seattle Wrap Up
Drupal Issue Question and Answer #138699
#138699 from the tagadelic_views issue queue:
Q: Is it possible for the landing page for the terms to be a view itself? so when a term is clicked out you could be taken to a sortable list?
A: A simple question became a complicated answer... You've really asked two questions.
For the first question, that is, to change the landing page for terms, you have the following options:
- Do it in the view -- override the taxonomy_term in the view
- Do it in the module -- implement a hook_term_path and return a different link for the term
- Do it in the theme -- implement a theme_tagadelic_weighted and output anything you want
For the second question, you used the word "sortable" instead of "sorted", which complicates the answer tremendously. I'm not sure what type of "sortable list" you want to show.
- You could create several of these views -- one for each of your sort criterion, and then modify the views header to link to each one. You'll want to use php code in the header and propagate the term-id to the URL for each view.
- If your output is a list, You'd also have to override the standard views table header output and replace it with one that uses the tablesort functions, and you'd have to extend the query using hook_views_query_alter... Hmm, sound like a nice new module, maybe another day :)
Option #1 -- do it in the view
From the admin/build/views page, add the 'taxonomy_term' default view. Customize the view to show your "sortable list" (See above). If all you want is a sorted list, change the sort criteria.
Option #2 -- do it in the module
The term URL is almost always created using taxonomy_term_path. This function can be overridden by vocabulary. You'd do this by writing a custom module. First, you want your custom module to update the vocabulary with your module name, and second you want your custom module to implement a hook_term_path. Here's the second part:
/**
* Implementation of hook_term_page
*
* Once you've hooked the vocabulary to your module, your module will
* get called here every time the taxonomy term path is wanted.
*
* You still need to implement the 'yourtaxonomy/term' in either a
* view or in code (see above comments about "sortable" verse "sorted.
*/
function yourmodule_term_path($term) {
return 'yourtaxonomy/term/'. $term->tid;
}
The first part can be done using mysql or code. The easiest thing to do is simply using mysql (replace vid=1 with your actually vocabulary-id):
mysql> UPDATE vocabulary SET module='yourmodule' WHERE vid=1;
But if you wanted to do this in a settings form, you could use:
/**
* Implementation of hook_menu().
*/
function yourmodule_menu() {
if ($may_cache) {
// add the url for a settings form
$items[] = array(
'path' => 'admin/settings/yourmodule',
'title' => t('Your Module'),
'description' => t('Settings for Your Custom Module'),
'callback' => 'drupal_get_form',
'callback arguments' => 'yourmodule_admin_settings',
'access' => user_access('administer site configuration'),
);
}
return $items;
}
/**
* settings form to allow the admin to select the vocabulary
*/
function yourmodule_admin_settings() {
$vocabularies = taxonomy_get_vocabularies();
foreach ($vocabularies as $vocab) {
$options[$vocab->vid] = $vocab->name;
}
$form['yourmodule_issue_vocab'] = array(
'#type' => 'select',
'#title' => t('Your Module Vocabulary'),
'#default_value' => variable_get('yourmodule_vocab', 0);
'#options' => $options,
'#description' => t('Select the vocabulary'),
);
$form['#submit']['yourmodule_settings_form_submit'] = array();
return $form;
}
/**
* Settings form handler
*
* This is really the reason for all of the above code...
*
* We need to update the vocabularies module, and everything above
* exists solely to provide a friendly User Interface for this.
*
* You could, of course, skip all this and simply update the
* {vocabulary} table in the database.
*/
function yourmodule_settings_form_submit($form_id, &$form_values) {
// update the vocabulary module so that it will use our term_path
db_query("UPDATE {vocabulary} SET module='taxonomy' WHERE module='yourmodule'");
if (isset($form_values['yourmodule_vocab'])) {
db_query("UPDATE {vocabulary} SET module='yourmodule' WHERE vid=%d", $form_values['yourmodule_vocab']);
}
}
Option #3 -- do it in the theme
Most Drupal output is displayed using over-ridable theme functions. These are functions that begin with theme_ and you can see them throughout the Drupal core and contrib modules. Drupal themes are the place to override these functions.
Copy the theme_tagadelic_weighted function from tagadelic.module into your theme's template.php. When you copy the function, change the name from theme_tagadelic_weighted to _phptemplate_tagadelic_weighted. Then change the output portion of this code to be whatever you want. So, your final function might look like:
function _phptemplate_tagadelic_weighted($terms) {
foreach ($terms as $term) {
$output .= l($term->name, 'yourviewurl', array('class'=>"tagadelic level$term->weight"), 'tid='. $term->tid) ." \n";
}
return $output;
}
(You could have also named your function using your theme name instead of _phptemplate. For example, if you are using the garland theme, you can name your function garland_tagadelic_weighted).
In Summary
If I needed a "sorted" list, I'd simply use option 1 and override the view. If I didn't want to do this for all vocabularies, I'd use a combination of the above, that is, create a taxonomy based view on yourviewurl, and use either option 2 or option 3 to force your URL's to link to it.
- doug's blog
- Login or register to post comments
- Delicious
- Digg
- Technorati






- which is basically the same as Option 2, but without needing custom code is to use Taxonomy Redirect - http://drupal.org/project/taxonomy_redirect
This can be used to redirect links for any vocabulary to an arbitrary path, so you can set up a view on that path with a term argument and you are all set.
I think this option is pretty nice, especially if you don't want to change the view of all taxonomy listings by overriding the taxonomy/term path.