New module 'Custom breadcrumbs'
This commit is contained in:
parent
89b4aad0f8
commit
3813ae0e06
26 changed files with 6004 additions and 0 deletions
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
// $Id: custom_breadcrumbs_taxonomy.admin.inc,v 1.1.2.8 2010/04/25 20:52:23 mgn Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administration pages for custom_breadcrumbs_taxonomy.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form builder; Displays an edit form for a custom breadcrumb taxonomy term record.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see custom_breadcrumbs_form_validate()
|
||||
* @see custom_breadcrumbs_form_submit()
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_term_form(&$form_state, $type) {
|
||||
$form = array();
|
||||
$bid = arg(5);
|
||||
$breadcrumb = NULL;
|
||||
if (isset($bid)) {
|
||||
drupal_set_title(t('Edit Custom Breadcrumb for Taxonomy Term'));
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_term', array('bid' => $bid));
|
||||
$breadcrumb = array_pop($breadcrumbs);
|
||||
}
|
||||
else {
|
||||
drupal_set_title(t('Add Custom Breadcrumb for Taxonomy Term'));
|
||||
}
|
||||
$options = taxonomy_form_all(TRUE);
|
||||
|
||||
$form['tid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Taxonomy Term'),
|
||||
'#options' => $options,
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Select the taxonomy term to apply this breadcrumb to'),
|
||||
'#default_value' => isset($breadcrumb->tid) ? $breadcrumb->tid : NULL,
|
||||
'#weight' => -10,
|
||||
);
|
||||
|
||||
$form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
|
||||
|
||||
$taxonomy_breadcrumbs_mode = variable_get('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE);
|
||||
if ($taxonomy_breadcrumbs_mode) {
|
||||
// Limit one title and path per taxonomy term.
|
||||
$form['titles'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Title'),
|
||||
'#required' => FALSE,
|
||||
'#description' => t('Specify the Title to use for the term breadcrumb. Leave blank to use the term name. Disable the <em>use taxonomy hierarchy</em> option on the <a href="@link">Custom Breadcrumbs Settings</a> page if you would prefer to specify several titles/paths for the breadcrumb.', array('@link' => url('admin/settings/custom-breadcrumbs'))),
|
||||
'#default_value' => isset($breadcrumb->titles) ? $breadcrumb->titles : NULL,
|
||||
);
|
||||
$form['paths'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Path'),
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Specify the Drupal path that the taxonomy term will be linked to. Currently operating in taxonomy breadcrumbs mode. Disable the <em>use taxonomy hierarchy</em> option on the <a href="@link">Custom Breadcrumbs Settings</a> page if you would prefer to specify several titles/paths for the breadcrumb.', array('@link' => url('admin/settings/custom-breadcrumbs'))),
|
||||
'#default_value' => isset($breadcrumb->paths) ? $breadcrumb->paths : NULL,
|
||||
);
|
||||
}
|
||||
|
||||
$form['#module'] = 'custom_breadcrumbs_taxonomy';
|
||||
$form['#infokey'] = 'taxonomy_term';
|
||||
$form['#submit'][] = 'custom_breadcrumbs_form_submit';
|
||||
$form['#validate'][] = 'custom_breadcrumbs_form_validate';
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Displays an edit form for a custom breadcrumb taxonomy vocabulary record.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see custom_breadcrumbs_form_validate()
|
||||
* @see custom_breadcrumbs_form_submit()
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_vocabulary_form(&$form_state, $type) {
|
||||
$form = array();
|
||||
$bid = arg(5);
|
||||
$breadcrumb = NULL;
|
||||
if (isset($bid)) {
|
||||
drupal_set_title(t('Edit Custom Breadcrumb for Taxonomy Vocabulary'));
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_vocabulary', array('bid' => $bid));
|
||||
$breadcrumb = array_pop($breadcrumbs);
|
||||
}
|
||||
else {
|
||||
drupal_set_title(t('Add Custom Breadcrumb for Taxonomy Vocabulary'));
|
||||
}
|
||||
|
||||
// Get a list of all vocabularies.
|
||||
$vocabularies = taxonomy_get_vocabularies();
|
||||
$options = array();
|
||||
foreach ($vocabularies as $vid => $vocabulary) {
|
||||
$options[$vid] = $vocabulary->name;
|
||||
}
|
||||
$form['vid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Vocabulary'),
|
||||
'#options' => $options,
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Select the taxonomy vocabulary to apply this breadcrumb to.'),
|
||||
'#default_value' => isset($breadcrumb->vid) ? $breadcrumb->vid : NULL,
|
||||
'#weight' => -10,
|
||||
);
|
||||
|
||||
$form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
|
||||
|
||||
$taxonomy_breadcrumbs_mode = variable_get('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE);
|
||||
if ($taxonomy_breadcrumbs_mode) {
|
||||
// Limit one title and path per taxonomy vocabulary.
|
||||
$form['titles'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Title'),
|
||||
'#required' => FALSE,
|
||||
'#description' => t('Specify the Title to use for the vocabulary breadcrumb. Leave blank to use the vocabulary name. Disable the <em>use taxonomy hierarchy</em> option on the <a href="@link">Custom Breadcrumbs Settings</a> page if you would prefer to specify several titles/paths for the breadcrumb.', array('@link' => url('admin/settings/custom-breadcrumbs'))),
|
||||
'#default_value' => isset($breadcrumb->titles) ? $breadcrumb->titles : NULL,
|
||||
);
|
||||
$form['paths'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Path'),
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Specify the Drupal path that the taxonomy vocabulary will be linked to. Currently operating in taxonomy breadcrumbs mode. Disable the <em>use taxonomy hierarchy</em> option on the <a href="@link">Custom Breadcrumbs Settings</a> page if you would prefer to specify several titles/paths for the breadcrumb.', array('@link' => url('admin/settings/custom-breadcrumbs'))),
|
||||
'#default_value' => isset($breadcrumb->paths) ? $breadcrumb->paths : NULL,
|
||||
);
|
||||
}
|
||||
$form['#module'] = 'custom_breadcrumbs_taxonomy';
|
||||
$form['#infokey'] = 'taxonomy_vocabulary';
|
||||
$form['#submit'][] = 'custom_breadcrumbs_form_submit';
|
||||
$form['#validate'][] = 'custom_breadcrumbs_form_validate';
|
||||
return $form;
|
||||
}
|
|
@ -0,0 +1,391 @@
|
|||
<?php
|
||||
// $Id: custom_breadcrumbs_taxonomy.inc,v 1.1.2.19 2010/12/30 18:36:25 mgn Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Helper functions for custom_breadcrumbs_taxonomy.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets a taxonomy breadcrumb and calls the original taxonomy/term/% callback.
|
||||
*
|
||||
* @param $callback
|
||||
* A callback function as defined in hook_menu().
|
||||
* @param $file
|
||||
* A callback file as defined in hook_menu().
|
||||
* @param $filepath
|
||||
* A callback file path as defined in hook_menu().
|
||||
* @param $str_tids
|
||||
* A term selector string, e.g. "1,3,8" or "4+9".
|
||||
* @param ...
|
||||
* Additional arguments to pass on to the callback.
|
||||
*
|
||||
* @return
|
||||
* The return value of the original callback function.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_term_page($str_tids, $callback, $file, $filepath) {
|
||||
$args = array_slice(func_get_args(), 4);
|
||||
|
||||
// Use first term to generate breadcrumb trail.
|
||||
$tids = taxonomy_terms_parse_string($str_tids);
|
||||
$terms = array();
|
||||
foreach ($tids['tids'] as $tid) {
|
||||
$term = taxonomy_get_term($tid);
|
||||
if ($term) {
|
||||
$terms[$term->tid] = $term;
|
||||
}
|
||||
}
|
||||
if (is_file($filepath . '/' . $file)) {
|
||||
require_once($filepath . '/' . $file);
|
||||
}
|
||||
$output = call_user_func_array($callback, $args);
|
||||
_custom_breadcrumbs_taxonomy_set_breadcrumb($tids['tids'][0], NULL, TRUE, array(), $terms);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the breadcrumb using a node's taxonomy.
|
||||
*
|
||||
* @param $tid
|
||||
* A taxonomy id.
|
||||
* @param $vid
|
||||
* A taxonomy vocabulary id.
|
||||
* @param $is_term_page
|
||||
* TRUE if the breadcrumb is being prepared for the taxonomy term page, FALSE otherwise.
|
||||
* @param $objs
|
||||
* An optional array of objects to be used for token replacement.
|
||||
* @param $terms
|
||||
* An array of taxonomy terms to use (potentially) to construct the breadcrumb.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_set_breadcrumb($tid, $vid = NULL, $is_term_page = FALSE, $objs = array(), $terms = array()) {
|
||||
if (variable_get('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE) && (!custom_breadcrumbs_exclude_path())) {
|
||||
$breadcrumb = custom_breadcrumbs_taxonomy_generate_breadcrumb($tid, $vid, $is_term_page, $objs);
|
||||
if ($is_term_page) {
|
||||
_custom_breadcrumbs_taxonomy_recent_term($tid);
|
||||
}
|
||||
if (variable_get('custom_breadcrumbs_taxonomy_include_node_title', FALSE) && isset($objs['node'])) {
|
||||
$breadcrumb[] = check_plain($objs['node']->title);
|
||||
}
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
// Optionally save the unique breadcrumb id of the last set breadcrumb.
|
||||
custom_breadcrumbs_unique_breadcrumb_id('taxonomy');
|
||||
}
|
||||
else {
|
||||
global $language;
|
||||
$languages = array('language' => $language->language, 'all' => '');
|
||||
// Check each term to see if it has a custom breadcrumb.
|
||||
$vids = array();
|
||||
if (!empty($terms)) {
|
||||
foreach ($terms as $term) {
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_term', array('tid' => $term->tid), $languages);
|
||||
$objs['taxonomy'] = $term;
|
||||
if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, $objs)) {
|
||||
custom_breadcrumbs_set_breadcrumb($breadcrumb, $objs);
|
||||
_custom_breadcrumbs_taxonomy_recent_term($term->tid);
|
||||
return;
|
||||
}
|
||||
if (!isset($vids[$term->vid])) {
|
||||
$vids[$term->vid] = $term;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($vids) && !is_null($vid)) {
|
||||
$vids[$vid] = NULL;
|
||||
}
|
||||
// No terms match, look for a match on the taxonomy vocabulary.
|
||||
foreach ($vids as $vid => $term) {
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_vocabulary', array('vid' => $vid), $languages);
|
||||
$objs['taxonomy'] = $term;
|
||||
if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, $objs)) {
|
||||
custom_breadcrumbs_set_breadcrumb($breadcrumb, $objs);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previous selected term or the lightest term for a given node.
|
||||
*
|
||||
* @param $node
|
||||
* The node object.
|
||||
*
|
||||
* @return
|
||||
* The taxonomy term object.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_node_get_term($node) {
|
||||
// First try to see if a recently viewed term matches one of the node's terms.
|
||||
$term = custom_breadcrumbs_taxonomy_node_get_recent_term($node);
|
||||
// If not, then select the nodes lightest term.
|
||||
if (is_null($term)) {
|
||||
$term = custom_breadcrumbs_taxonomy_node_get_lightest_term($node);
|
||||
}
|
||||
return $term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most recently selected term for a given node.
|
||||
*
|
||||
* @param $node
|
||||
* The node object.
|
||||
*
|
||||
* @return
|
||||
* The previously selected taxonomy term object that also belongs to the node.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_node_get_recent_term($node) {
|
||||
$terms = taxonomy_node_get_terms($node);
|
||||
$tid = _custom_breadcrumbs_taxonomy_recent_term();
|
||||
if (is_array($terms) && !empty($terms) && !is_null($tid)) {
|
||||
return (isset($terms[$tid])) ? taxonomy_get_term($tid) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or returns the previous selected term id.
|
||||
*
|
||||
* @param $tid
|
||||
* An optional term id to store in the session variable to establish a term history.
|
||||
*
|
||||
* @return
|
||||
* If this function is called without a term id, then it will return the previously
|
||||
* selected taxonomy term id, retrieved from the session variable.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_recent_term($tid = NULL) {
|
||||
if (!is_null($tid)) {
|
||||
$_SESSION['custom_breadcrumbs_previous_term'] = $tid;
|
||||
}
|
||||
elseif (isset($_SESSION['custom_breadcrumbs_previous_term'])) {
|
||||
return $_SESSION['custom_breadcrumbs_previous_term'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the lightest term for a given node.
|
||||
*
|
||||
* If the term has parents, then the lightest parent's weight is used for the
|
||||
* term weight. And if the parent has multiple child terms at different depths,
|
||||
* the deepest child term will be returned. If the child terms have the same
|
||||
* depth, then the lightest child term is returned.
|
||||
*
|
||||
* @param $node
|
||||
* The node object.
|
||||
*
|
||||
* @return
|
||||
* The taxonomy term object.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_node_get_lightest_term($node) {
|
||||
$terms = taxonomy_node_get_terms($node);
|
||||
if (!empty($terms)) {
|
||||
if (count($terms) > 1) {
|
||||
foreach ($terms as $term) {
|
||||
// Only consider terms in the lightest vocabulary.
|
||||
if (!isset($vid)) {
|
||||
$vid = $term->vid;
|
||||
}
|
||||
elseif ($term->vid != $vid) continue;
|
||||
// If the term has parents, the weight of the term is the weight of the lightest parent.
|
||||
$parents = taxonomy_get_parents_all($term->tid);
|
||||
$depth = count($parents);
|
||||
if ($depth > 0) {
|
||||
$parent = array_pop($parents);
|
||||
$weight = $parent->weight;
|
||||
}
|
||||
else {
|
||||
$weight = $term->weight;
|
||||
}
|
||||
if ((isset($lweight) && ($weight < $lweight)) || !isset($lweight)) {
|
||||
$lterm = $term;
|
||||
$lweight = $weight;
|
||||
$ldepth = $depth;
|
||||
}
|
||||
elseif (isset($lweight) && ($weight == $lweight)) {
|
||||
// If the node has multiple child terms with the same parent, choose the child with the greatest depth.
|
||||
if ($depth > $ldepth) {
|
||||
$lterm = $term;
|
||||
$ldepth = $depth;
|
||||
}
|
||||
elseif ($depth == $ldepth) {
|
||||
// If the terms have the same depth, pick the term with the lightest weight.
|
||||
$lterm = ($lterm->weight < $term->weight) ? $lterm : $term;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $lterm;
|
||||
}
|
||||
else {
|
||||
return array_pop($terms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a breadcrumb from the taxonomy hierarchy of the term id or vocab id.
|
||||
* This will only be called if custom_breadcrumbs_taxonomy_use_hierarchy has been enabled.
|
||||
*
|
||||
* @param $tid
|
||||
* A taxonomy id.
|
||||
* @param $vid
|
||||
* A taxonomy vocabulary id.
|
||||
* @param $is_term_page
|
||||
* TRUE if the breadcrumb is being prepared for the taxonomy term page, FALSE otherwise.
|
||||
* @param $objs
|
||||
* An optional array of objects to be used for token replacement.
|
||||
*
|
||||
* @return
|
||||
* The breadcrumb trail.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_generate_breadcrumb($tid, $vid = NULL, $is_term_page = FALSE, $objs = NULL) {
|
||||
$term = (is_null($tid)) ? NULL : taxonomy_get_term($tid);
|
||||
$vocabid = (!is_null($vid)) ? $vid : (is_null($term) ? NULL : $term->vid);
|
||||
$types = NULL;
|
||||
if (module_exists('token')) {
|
||||
$objs['taxonomy'] = $term;
|
||||
$types = custom_breadcrumbs_token_types($objs);
|
||||
}
|
||||
$trail = array();
|
||||
$trail = _custom_breadcrumbs_taxonomy_home_trail();
|
||||
|
||||
if (!is_null($vocabid)) {
|
||||
$vocab_trail = _custom_breadcrumbs_taxonomy_vocabulary_trail($vocabid, $is_term_page, $objs, $types, count($trail));
|
||||
$trail = array_merge($trail, $vocab_trail);
|
||||
}
|
||||
|
||||
if (!is_null($tid)) {
|
||||
$term_trail = _custom_breadcrumbs_taxonomy_term_trail($tid, $is_term_page, $objs, $types, count($trail));
|
||||
$trail = array_merge($trail, $term_trail);
|
||||
// Optionally remove the current TERM from end of breadcrumb trail.
|
||||
if ((!variable_get('custom_breadcrumbs_taxonomy_show_current_term', TRUE) || ($is_term_page && !variable_get('custom_breadcrumbs_taxonomy_show_current_term_term', FALSE))) && (count($trail) > 1)) {
|
||||
array_pop($trail);
|
||||
}
|
||||
}
|
||||
return $trail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates configurable string when i18ntaxonomy module is installed.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_tt($string_id, $default, $language = NULL) {
|
||||
return function_exists('tt') ? tt($string_id, $default, $language) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the home breadcrumb trail.
|
||||
*
|
||||
* @return
|
||||
* The breadcrumb trail.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_home_trail() {
|
||||
$trail = array();
|
||||
if (variable_get('custom_breadcrumbs_taxonomy_append_breadcrumb', FALSE)) {
|
||||
// Check to see if a breadcrumb has already been defined.
|
||||
$trail = drupal_get_breadcrumb();
|
||||
}
|
||||
else {
|
||||
$trail = custom_breadcrumbs_home_crumb();
|
||||
}
|
||||
return $trail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the vocabulary trail.
|
||||
*
|
||||
* @param $vid
|
||||
* A taxonomy vocabulary id.
|
||||
* @param $is_term_page
|
||||
* TRUE if the breadcrumb is being prepared for the taxonomy term page, FALSE otherwise.
|
||||
* @param $objs
|
||||
* An optional array of objects to be used to determine breadcrumb visibility and for token replacement.
|
||||
* @param $types
|
||||
* An array of token types to be used in token replacement.
|
||||
* @param $part
|
||||
* A postive integer indicating the breadcrumb segment (home crumb = 0).
|
||||
*
|
||||
* @return
|
||||
* The breadcrumb trail.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_vocabulary_trail($vid, $is_term_page = FALSE, $objs = array(), $types = array('global' => NULL), $part = 1) {
|
||||
// Generate the VOCABULARY breadcrumb.
|
||||
$trail = array();
|
||||
// Check to see if a vocabulary breadcrumb exists.
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_vocabulary', array('vid' => $vid));
|
||||
$vocabulary_path = NULL;
|
||||
$title = NULL;
|
||||
$bid = NULL;
|
||||
if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, $objs)) {
|
||||
$vocabulary_path = $breadcrumb->paths;
|
||||
$title = $breadcrumb->titles;
|
||||
$bid = $breadcrumb->bid;
|
||||
if (module_exists('token')) {
|
||||
$vocabulary_path = token_replace_multiple($vocabulary_path, $types);
|
||||
$title = token_replace_multiple($title, $types);
|
||||
}
|
||||
}
|
||||
if ($title == NULL) {
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
$title = _custom_breadcrumbs_taxonomy_tt("taxonomy:vocabulary:$vid:name", $vocabulary->name);
|
||||
}
|
||||
if ($vocabulary_path != NULL) {
|
||||
$options = _custom_breadcrumbs_identifiers_option($part, $bid);
|
||||
$trail = array(l($title, $vocabulary_path, $options));
|
||||
}
|
||||
elseif (variable_get('custom_breadcrumbs_taxonomy_show_vocabulary', FALSE)) {
|
||||
$trail = array(check_plain($title));
|
||||
}
|
||||
return $trail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the taxonomy term trail.
|
||||
*
|
||||
* @param $tid
|
||||
* A taxonomy term id.
|
||||
* @param $is_term_page
|
||||
* TRUE if the breadcrumb is being prepared for the taxonomy term page, FALSE otherwise.
|
||||
* @param $objs
|
||||
* An optional array of objects to be used to determine breadcrumb visibility and for token replacement.
|
||||
* @param $types
|
||||
* An array of token types to be used in token replacement.
|
||||
* @param $part
|
||||
* A postive integer indicating the breadcrumb segment (home crumb = 0).
|
||||
*
|
||||
* @return
|
||||
* The breadcrumb trail.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_term_trail($tid, $is_term_page = FALSE, $objs = array(), $types = array('global' => NULL), $part = 1) {
|
||||
// Generate the TERM breadcrumb.
|
||||
$trail = array();
|
||||
$parent_terms = array_reverse(taxonomy_get_parents_all($tid));
|
||||
foreach ($parent_terms as $parent_term) {
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_term', array('tid' => $parent_term->tid));
|
||||
$term_path = NULL;
|
||||
$title = NULL;
|
||||
$bid = NULL;
|
||||
if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, $objs)) {
|
||||
$term_path = $breadcrumb->paths;
|
||||
$title = $breadcrumb->titles;
|
||||
$bid = $breadcrumb->bid;
|
||||
if (module_exists('token')) {
|
||||
$term_path = token_replace_multiple($term_path, $types);
|
||||
$title = token_replace_multiple($title, $types);
|
||||
}
|
||||
}
|
||||
if ($title == NULL) {
|
||||
$title = _custom_breadcrumbs_taxonomy_tt("taxonomy:term:$parent_term->tid:name", $parent_term->name);
|
||||
}
|
||||
if ($term_path == NULL) {
|
||||
$term_path = taxonomy_term_path(taxonomy_get_term($parent_term->tid));
|
||||
}
|
||||
|
||||
// Do not create links to own self if we are on a taxonomy/term page.
|
||||
if ($is_term_page && $parent_term->tid == $tid) {
|
||||
$trail[] = check_plain($title);
|
||||
}
|
||||
else {
|
||||
$options = _custom_breadcrumbs_identifiers_option($part, $bid);
|
||||
$trail[] = l($title, $term_path, $options);
|
||||
}
|
||||
++$part;
|
||||
}
|
||||
return $trail;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
; $Id: custom_breadcrumbs_taxonomy.info,v 1.1.2.2 2009/05/30 22:02:07 mgn Exp $
|
||||
name = Custom Breadcrumbs for Taxonomy
|
||||
description = "Enables taxonomy based breadcrumbs and allows for node assosciations with taxonomy terms."
|
||||
package = Custom Breadcrumbs
|
||||
dependencies[] = custom_breadcrumbs
|
||||
dependencies[] = taxonomy
|
||||
core = 6.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-01-08
|
||||
version = "6.x-2.0-rc1"
|
||||
core = "6.x"
|
||||
project = "custom_breadcrumbs"
|
||||
datestamp = "1294462254"
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
// $Id: custom_breadcrumbs_taxonomy.install,v 1.1.2.10 2011/01/08 03:53:17 mgn Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install file for the custom_breadcrumbs_taxonomy module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_install() {
|
||||
// Create tables.
|
||||
drupal_install_schema('custom_breadcrumbs_taxonomy');
|
||||
|
||||
// If taxonomy_breadcrumbs is installed, copy term and vocab breadcrumb to custom_breadcrumbs_taxonomy tables.
|
||||
if (module_exists('taxonomy_breadcrumb')) {
|
||||
// Search for taxonomy_breadcrumb term and vocabulary breadcrumbs and copy to new custom_breadcrumb_taxonomy tables.
|
||||
drupal_set_message('Taxonomy breadcrumb module is enabled. Copying breadcrumbs from {taxonomy_breadcrumb_term} and {taxonomy_breadcrumb_vocabulary} to custom_breadcrumbs_taxonomy ...');
|
||||
$result = db_query("SELECT * FROM {taxonomy_breadcrumb_term}");
|
||||
$found = 0;
|
||||
while ($breadcrumb = db_fetch_object($result)) {
|
||||
db_query("INSERT INTO {custom_breadcrumbs_taxonomy_term} (paths, tid) VALUES ('%s', %d)", $breadcrumb->path, $breadcrumb->tid);
|
||||
++$found;
|
||||
}
|
||||
$result = db_query("SELECT * FROM {taxonomy_breadcrumb_vocabulary}");
|
||||
|
||||
while ($breadcrumb = db_fetch_object($result)) {
|
||||
db_query("INSERT INTO {custom_breadcrumbs_taxonomy_vocabulary} (paths, vid) VALUES ('%s', %d)", $breadcrumb->path, $breadcrumb->vid);
|
||||
++$found;
|
||||
}
|
||||
|
||||
// use variable definitions already set for taxonomy_breadcrumb
|
||||
variable_set('custom_breadcrumbs_taxonomy_home', variable_get('taxonomy_breadcrumb_home', t('Home')));
|
||||
variable_set('custom_breadcrumbs_taxonomy_show_current_term', variable_get('taxonomy_breadcrumb_show_current_term', TRUE));
|
||||
variable_set('custom_breadcrumbs_taxonomy_include_node_title', variable_get('taxonomy_breadcrumb_include_node_title', FALSE));
|
||||
variable_set('custom_breadcrumbs_taxonomy_include_nodes', variable_get('taxonomy_breadcrumb_include_nodes', FALSE));
|
||||
variable_set('custom_breadcrumbs_taxonomy_node_types', variable_get('taxonomy_breadcrumb_node_types', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT));
|
||||
define('CUSTOM_BREADCRUMBS_TAXONOMY_NODE_TYPES_DEFAULT', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT);
|
||||
|
||||
// Set custom_breadcrumbs_taxonomy to use taxonomy hierarchy in constructing breadcrumb.
|
||||
variable_set('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE);
|
||||
|
||||
if ($found > 0) {
|
||||
drupal_set_message(format_plural($found, 'Copied 1 breadcrumb.', 'Copied @count breadcrumbs.'));
|
||||
drupal_set_message(t('You can now disable taxonomy_breadcrumb, and test custom_breadcrumb_taxonomy.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('No taxonomy_breadcrumbs were found'));
|
||||
}
|
||||
}
|
||||
drupal_set_message('Custom Breadcrumbs for Taxonomy Terms and Vocabularies: Taxonomy based breadcrumbs should now appear on node pages and taxonomy/term pages. For the most common applications this module will work "out of the box" and no further configuration is necessary. If customization is desired settings can be changed on the '. l('administration page', 'admin/settings/custom-breadcrumbs') .'.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_uninstall() {
|
||||
// Remove tables.
|
||||
drupal_uninstall_schema('custom_breadcrumbs_taxonomy');
|
||||
|
||||
// Remove persistent variables.
|
||||
variable_del('custom_breadcrumbs_taxonomy_use_hierarchy');
|
||||
variable_del('custom_breadcrumbs_taxonomy_append_breadcrumb');
|
||||
variable_del('custom_breadcrumbs_taxonomy_show_vocabulary');
|
||||
variable_del('custom_breadcrumbs_taxonomy_show_current_term');
|
||||
variable_del('custom_breadcrumbs_taxonomy_show_current_term_term');
|
||||
variable_del('custom_breadcrumbs_taxonomy_include_node_title');
|
||||
variable_del('custom_breadcrumbs_taxonomy_include_nodes');
|
||||
variable_del('custom_breadcrumbs_taxonomy_node_types');
|
||||
variable_del('custom_breadcrumbs_taxonomy_views');
|
||||
variable_del('custom_breadcrumbs_taxonomy_result_nodes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_schema() {
|
||||
$schema['custom_breadcrumbs_taxonomy_term'] = array(
|
||||
'description' => 'Stores custom breadcrumbs for taxonomy terms',
|
||||
'fields' => array(
|
||||
'bid' => array(
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Unique identifier for the {custom_breadcrumbs_taxonomy} breadcrumbs.',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => FALSE,
|
||||
'description' => 'An optional name for the custom breadcrumb.',
|
||||
),
|
||||
'titles' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'A title for the breadcrumb link.',
|
||||
),
|
||||
'paths' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'description' => 'A path for the breadcrumb link.',
|
||||
),
|
||||
'tid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'The taxonomy term id for this breadcrumb.',
|
||||
),
|
||||
|
||||
'visibility_php' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'medium',
|
||||
'description' => 'An optional PHP snippet to control the {custom_breadcrumbs_views} visibility.',
|
||||
),
|
||||
'language' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The language this breadcrumb is for; if blank, the breadcrumb will be used for unknown languages.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'language' => array('language'),
|
||||
'tid_language' => array('tid', 'language'),
|
||||
),
|
||||
'primary key' => array('bid'),
|
||||
);
|
||||
|
||||
$schema['custom_breadcrumbs_taxonomy_vocabulary'] = array(
|
||||
'description' => 'Stores custom breadcrumbs for taxonomy vocabularies',
|
||||
'fields' => array(
|
||||
'bid' => array(
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Unique identifier for the {custom_breadcrumbs_taxonomy} breadcrumbs.',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => FALSE,
|
||||
'description' => 'An optional name for the custom breadcrumb.',
|
||||
),
|
||||
'titles' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'A titles for the breadcrumb link.',
|
||||
),
|
||||
'paths' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'description' => 'A paths for the breadcrumb link.',
|
||||
),
|
||||
'vid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'description' => 'The taxonomy vocabulary id for this breadcrumb.',
|
||||
),
|
||||
'visibility_php' => array(
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'medium',
|
||||
'description' => 'An optional PHP snippet to control the {custom_breadcrumbs_views} visibility.',
|
||||
),
|
||||
'language' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 12,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The language this breadcrumb is for; if blank, the breadcrumb will be used for unknown languages.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'language' => array('language'),
|
||||
'vid_language' => array('vid', 'language'),
|
||||
),
|
||||
'primary key' => array('bid'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weight of custom_breadcrumbs_taxonomy to be greater than taxonomy, views, and custom_breadcrumbs.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_update_6000() {
|
||||
$ret = array();
|
||||
$tax_weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
|
||||
$views_weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'views'"));
|
||||
$cb_weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'custom_breadcrumbs'"));
|
||||
$cb_tax_weight = max($tax_weight, $views_weight, $cb_weight) + 2;
|
||||
$ret[] = update_sql("UPDATE {system} SET weight = ". $cb_tax_weight ." WHERE name = 'custom_breadcrumbs_taxonomy'");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds name field for improved organization of breadcrumbs
|
||||
* Remove set_active_menu field because it is no longer used.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_update_6200() {
|
||||
$ret = array();
|
||||
db_add_field($ret, 'custom_breadcrumbs_taxonomy_term', 'name', array('type' => 'varchar', 'length' => 128, 'NOT NULL' => FALSE, 'description' => 'An optional name for the custom breadcrumb.'));
|
||||
db_add_field($ret, 'custom_breadcrumbs_taxonomy_vocabulary', 'name', array('type' => 'varchar', 'length' => 128, 'NOT NULL' => FALSE, 'description' => 'An optional name for the custom breadcrumb.'));
|
||||
|
||||
return $ret;
|
||||
}
|
|
@ -0,0 +1,529 @@
|
|||
<?php
|
||||
// $Id: custom_breadcrumbs_taxonomy.module,v 1.1.2.26 2010/12/30 18:36:25 mgn Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This module implements taxonomy_based breadcrumbs using a hybrid of methods
|
||||
* developed for the custom_breadcrumbs and taxonomy_breadcrumbs modules.
|
||||
* Breadcrumbs are provided for node and taxonomy term pages.
|
||||
* If 'Use taxonomy hierarchy' is checked on the custom_breadcrumbs settings
|
||||
* page, then the breadcrumb trail will be like
|
||||
* [HOME] >> [VOCABULARY] >> TERM >> [TERM] ...
|
||||
*
|
||||
* - The HOME breadcrumb (if present) links to the home page. The text
|
||||
* displayed for HOME is administrator configurable on the custom_breadcrumbs
|
||||
* settings page.
|
||||
* - The VOCABULARY breadcrumb (if present) will link to an administrator
|
||||
* defined page. If the VOCABULARY does not have an administrator
|
||||
* defined page, it will not appear in the breadcrumb trail.
|
||||
* - Each TERM breadcrumb will link to either
|
||||
* (1) taxonomy/term/tid by default, or
|
||||
* (2) an administrator defined page if one is defined for the term.
|
||||
*
|
||||
* Examples:
|
||||
* home >> term >> term
|
||||
* mysite >> term >> term
|
||||
* home >> vocabulary >> term >> term
|
||||
* vocabulary >> term >> term
|
||||
*
|
||||
* If 'Use taxonomy hierarchy' is not checked, then the titles and paths used to
|
||||
* construct the breadcrumb should be defined at the custom_breadcrumbs administration
|
||||
* page in the same as other custom breadcrumbs. For a node containing multiple terms
|
||||
* and vocabularies, the lightest term with a visible, matching custom breadcrumb is
|
||||
* selected. If a taxonomy_term custom breadcrumb is not found, then taxonomy_vocabulary
|
||||
* custom breadcrumbs are matched against the node's vocabularies.
|
||||
*/
|
||||
|
||||
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs.admin');
|
||||
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs_common');
|
||||
|
||||
// Default value for Advanced Settings, Node Types.
|
||||
define('CUSTOM_BREADCRUMBS_TAXONOMY_NODE_TYPES_DEFAULT', 'book');
|
||||
|
||||
/**
|
||||
* Implements hook_cb_breadcrumb_info().
|
||||
*
|
||||
* @return an array with elements
|
||||
* 'table' indicating the db_table to load the breadcrumb from,
|
||||
* 'field' a field of the database table used to identify the breadcrumb,
|
||||
* 'type' a string used for indicating the breadcrumb type on the admin list,
|
||||
* 'name_constructor' a function which generates the breadcrumb name from the breadcrumb.
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_cb_breadcrumb_info() {
|
||||
$breadcrumb_type_info = array();
|
||||
$breadcrumb_type_info['taxonomy_vocabulary'] = array(
|
||||
'table' => 'custom_breadcrumbs_taxonomy_vocabulary',
|
||||
'field' => 'vid',
|
||||
'type' => 'taxonomy_vocabulary',
|
||||
'name_constructor' => '_custom_breadcrumbs_taxonomy_vocabulary_breadcrumb_name'
|
||||
);
|
||||
$breadcrumb_type_info['taxonomy_term'] = array(
|
||||
'table' => 'custom_breadcrumbs_taxonomy_term',
|
||||
'field' => 'tid',
|
||||
'type' => 'taxonomy_term',
|
||||
'name_constructor' => '_custom_breadcrumbs_taxonomy_term_breadcrumb_name'
|
||||
);
|
||||
return $breadcrumb_type_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a name to display in the admin screen from the taxonomy term.
|
||||
*
|
||||
* @param $breadcrumb
|
||||
* The breadcrumb object.
|
||||
*
|
||||
* @return
|
||||
* A text string that will be used as the breadcrumb name.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_term_breadcrumb_name($breadcrumb) {
|
||||
$names = array();
|
||||
$parents = taxonomy_get_parents_all($breadcrumb->tid);
|
||||
while ($parent = array_shift($parents)) {
|
||||
$names[] = $parent->name;
|
||||
}
|
||||
$term = taxonomy_get_term($breadcrumb->tid);
|
||||
$vocabulary = taxonomy_vocabulary_load($term->vid);
|
||||
$names[] = $vocabulary->name;
|
||||
$names = array_reverse($names);
|
||||
$output = implode('>', $names);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a name to display in the admin screen from the taxonomy vocabulary.
|
||||
*
|
||||
* @param $breadcrumb
|
||||
* The breadcrumb object.
|
||||
*
|
||||
* @return
|
||||
* A text string that will be used as the breadcrumb name.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_vocabulary_breadcrumb_name($breadcrumb) {
|
||||
$vocabulary = taxonomy_vocabulary_load($breadcrumb->vid);
|
||||
return $vocabulary->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_menu() {
|
||||
$items = array();
|
||||
$items['admin/build/custom_breadcrumbs/taxonomy_term/add'] = array(
|
||||
'title' => 'Term',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_breadcrumbs_taxonomy_term_form', 'taxonomy_term'),
|
||||
'access arguments' => array('administer custom breadcrumbs'),
|
||||
'file' => 'custom_breadcrumbs_taxonomy.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 5,
|
||||
);
|
||||
$items['admin/build/custom_breadcrumbs/taxonomy_term/edit'] = array(
|
||||
'title' => 'Edit custom breadcrumb for taxonomy term',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_breadcrumbs_taxonomy_term_form', 'taxonomy_term'),
|
||||
'file' => 'custom_breadcrumbs_taxonomy.admin.inc',
|
||||
'access arguments' => array('administer custom breadcrumbs'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items['admin/build/custom_breadcrumbs/taxonomy_vocabulary/add'] = array(
|
||||
'title' => 'Vocabulary',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_breadcrumbs_taxonomy_vocabulary_form', 'taxonomy_vocabulary'),
|
||||
'access arguments' => array('administer custom breadcrumbs'),
|
||||
'file' => 'custom_breadcrumbs_taxonomy.admin.inc',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 5,
|
||||
);
|
||||
$items['admin/build/custom_breadcrumbs/taxonomy_vocabulary/edit'] = array(
|
||||
'title' => 'Edit custom breadcrumb for taxonomy vobaculary',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_breadcrumbs_taxonomy_vocabulary_form', 'taxonomy_vocabulary'),
|
||||
'access arguments' => array('administer custom breadcrumbs'),
|
||||
'file' => 'custom_breadcrumbs_taxonomy.admin.inc',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_nodeapi().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_nodeapi($node, $op, $teaser, $page) {
|
||||
if ($op == 'alter' && empty($teaser) && !empty($page)) {
|
||||
if (_custom_breadcrumbs_taxonomy_allowed_node_type($node->type)) {
|
||||
module_load_include('inc', 'custom_breadcrumbs_taxonomy');
|
||||
// Extract the most recently viewed term or the lightest term from lightest vocabulary assosciated with node.
|
||||
$term = custom_breadcrumbs_taxonomy_node_get_term($node);
|
||||
if ($term) {
|
||||
$terms = taxonomy_node_get_terms($node);
|
||||
_custom_breadcrumbs_taxonomy_set_breadcrumb($term->tid, $term->vid, FALSE, array('node' => $node), $terms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_alter().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_menu_alter(&$callbacks) {
|
||||
// This will not work if views or panels has overriden taxonomy/term/%
|
||||
if (isset($callbacks['taxonomy/term/%']) && ($callbacks['taxonomy/term/%']['page callback'] != 'views_page')) {
|
||||
$term_callback = &$callbacks['taxonomy/term/%'];
|
||||
$callback = $term_callback['page callback'];
|
||||
$arguments = $term_callback['page arguments'];
|
||||
$file = $term_callback['file'];
|
||||
$filepath = isset($term_callback['file path']) ? $term_callback['file path'] : drupal_get_path('module', $term_callback['module']);
|
||||
$term_callback['page callback'] = 'custom_breadcrumbs_taxonomy_term_page';
|
||||
$term_callback['page arguments'] = array_merge(array(2, $callback, $file, $filepath), $arguments);
|
||||
$term_callback['file'] = 'custom_breadcrumbs_taxonomy.inc';
|
||||
$term_callback['file path'] = drupal_get_path('module', 'custom_breadcrumbs_taxonomy');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_pre_render().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_views_pre_render(&$view) {
|
||||
if (variable_get('custom_breadcrumbs_taxonomy_views', FALSE)) {
|
||||
// Set the taxonomy breadcrumb for the view.
|
||||
if (isset($view->display) && !empty($view->display)) {
|
||||
$curpath = drupal_get_normal_path($_GET['q']);
|
||||
// A taxonomy term page is any page with path a component 'taxonomy' followed by 'term'.
|
||||
$arg_values = arg(NULL, $curpath);
|
||||
$is_term_page = FALSE;
|
||||
if (($key = array_search('taxonomy', $arg_values)) !== FALSE) {
|
||||
$is_term_page = (isset($arg_values[$key + 1]) && $arg_values[$key + 1] == 'term');
|
||||
}
|
||||
foreach ($view->display as $id => $display) {
|
||||
// Identify allowed displays for breadcrumb replacement.
|
||||
if (!_custom_breadcrumbs_allowed_display($display)) continue;
|
||||
$viewpath = _custom_breadcrumbs_construct_view_path($display);
|
||||
// Verify the view path matches the current path.
|
||||
if (_custom_breadcrumbs_match_path($curpath, $viewpath)) {
|
||||
// Select matching display with the greatest number of explicit arguments.
|
||||
$num = substr_count($display->display_options['path'], '%');
|
||||
if (!isset($max) || (isset($max) && ($num > $max))) {
|
||||
$max = $num;
|
||||
$max_id = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($max_id)) {
|
||||
$display = $view->display[$max_id];
|
||||
$arguments = _custom_breadcrumbs_views_display_arguments($display);
|
||||
if (isset($arguments) && !empty($arguments)) {
|
||||
$viewargs = (isset($display->handler->view->args) && is_array($display->handler->view->args)) ? $display->handler->view->args : array();
|
||||
$arg_values = _custom_breadcrumbs_views_parse_args($arguments, $viewargs);
|
||||
foreach ($arg_values['types'] as $key => $type) {
|
||||
$tid = NULL;
|
||||
$vid = NULL;
|
||||
switch ($type) {
|
||||
case 'tid':
|
||||
$tid = $arg_values['values'][$key];
|
||||
break;
|
||||
case 'vid':
|
||||
$vid = $arg_values['values'][$key];
|
||||
break;
|
||||
}
|
||||
if (!is_null($tid) || !is_null($vid)) {
|
||||
$terms = array();
|
||||
if (!is_null($tid)) {
|
||||
$term = taxonomy_get_term($tid);
|
||||
$vid = $term->vid;
|
||||
if ($term) {
|
||||
$terms[$term->tid] = $term;
|
||||
}
|
||||
}
|
||||
module_load_include('inc', 'custom_breadcrumbs_taxonomy');
|
||||
_custom_breadcrumbs_taxonomy_set_breadcrumb($tid, $vid, $is_term_page, array('view' => $view), $terms);
|
||||
if (!is_null($tid)) {
|
||||
_custom_breadcrumbs_taxonomy_recent_term($tid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Otherwise, optionally use the first result node that is of an allowed node type to generate the breadcrumb.
|
||||
if (variable_get('custom_breadcrumbs_taxonomy_result_nodes', FALSE) &&
|
||||
_custom_breadcrumbs_allowed_display($display) && !empty($view->result)) {
|
||||
foreach ($view->result as $result) {
|
||||
if (isset($result->nid)) {
|
||||
$node = node_load(array('nid' => $result->nid));
|
||||
if (_custom_breadcrumbs_taxonomy_allowed_node_type($node->type)) {
|
||||
module_load_include('inc', 'custom_breadcrumbs_taxonomy');
|
||||
$term = custom_breadcrumbs_taxonomy_node_get_term($node);
|
||||
if ($term) {
|
||||
$terms = taxonomy_node_get_terms($node);
|
||||
_custom_breadcrumbs_taxonomy_set_breadcrumb($term->tid, $term->vid, $is_term_page, array('node' => $node), $terms);
|
||||
_custom_breadcrumbs_taxonomy_recent_term($term->tid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/help#custom_breadcrumbs_taxonomy':
|
||||
$output = '<p>' . t('The custom_breadcrumbs_taxonomy module generates taxonomy-based breadcrumbs on node pages and taxonomy/term pages. The breadcrumb trail takes on the form:') . '</p>';
|
||||
$output .= '<p>' . t('[HOME] >> [VOCABULARY] >> TERM >> [TERM] ...') . '</p>';
|
||||
|
||||
$output .= '<ul>';
|
||||
$output .= '<li>' . t('The text displayed for HOME is configurable below. The <em>HOME</em> breadcrumb (if present) links to the homepage. The text displayed for HOME is configurable by an administrator. If the HOME breadcrumb is not defined by the administrator, it will not appear in the breadcrumb trail.') . '</li>';
|
||||
$output .= '<li>' . t('The <em>VOCABULARY</em> breadcrumb (if present) will link to an administrator defined page. If the VOCABULARY does not have an administrator defined page, it will not appear in the breadcrumb trail. This can be configured on the add/edit vocabulary pages within <a href="@taxonomy">administer >> categories</a> (taxonomy).', array('@taxonomy' => url('admin/content/taxonomy'))) . '</li>';
|
||||
$output .= '<li>' . t('Each <em>TERM</em> breadcrumb will link to either (1) taxonomy/term/tid by default, or (2) an administrator defined page if one is defined for the term. This can be configured on the add/edit term pages within <a href="@taxonomy">administer >> categories</a> (taxonomy).', array('@taxonomy' => url('admin/content/taxonomy'))) . '</li>';
|
||||
$output .= '</ul>';
|
||||
|
||||
$output .= '<h3>' . t('Examples:') . '</h3>';
|
||||
$output .= '<ul>';
|
||||
$output .= '<li>' . t('home >> term >> term') . '</li>';
|
||||
$output .= '<li>' . t('mysite >> term >> term') . '</li>';
|
||||
$output .= '<li>' . t('home >> vocabulary >> term >> term') . '</li>';
|
||||
$output .= '<li>' . t('vocabulary >> term >> term') . '</li>';
|
||||
$output .= '</ul>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_form_alter(&$form, $form_state, $form_id) {
|
||||
if ($form_id == 'custom_breadcrumbs_admin_settings') {
|
||||
$form['settings']['custom_breadcrumbs_taxonomy'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Taxonomy structure'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_use_hierarchy'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use the taxonomy hierarchy to set the breadcrumb trail for nodes and taxonomy pages'),
|
||||
'#description' => t('If selected, the custom breadcrumb trail will be constructed from the taxonomy vocabulary and terms associated with the node. Breadcrumb titles will be selected from taxonomy term and vocabulary names.'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE),
|
||||
'#weight' => 10,
|
||||
);
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_append_breadcrumb'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Append taxonomy breadcrumb trail to current breadcrumb for selected node types'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_append_breadcrumb', FALSE),
|
||||
'#description' => t('If enabled along with the taxonomy hierarchy option (above), the taxonomy breadcrumb trail will be appended to the current breadcrumb trail.'),
|
||||
'#weight' => 20,
|
||||
);
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_show_vocabulary'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show vocabulary in breadcrumb trail'),
|
||||
'#description' => t('If enabled, the vocabulary name will be shown in the breadcrumb trail, even when a custom breadcrumb has not been defined for the vocabulary. In this case the crumb will not be linked. If a custom breadcrumb has been defined for the vocabulary, it will be displayed whether or not this option is enabled.'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_show_vocabulary', FALSE),
|
||||
'#weight' => 25,
|
||||
);
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_show_current_term'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show current taxonomy term in breadcrumb trail for node pages'),
|
||||
'#description' => t('If enabled, the lightest term associated with node is shown as the last breadcrumb in the breadcrumb trail. Otherwise, the only terms shown in the breadcrumb trail are parent terms (if any parents exist). The recommended setting is enabled.'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_show_current_term', TRUE),
|
||||
'#weight' => 30,
|
||||
);
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_show_current_term_term'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show current taxonomy term in breadcrumb trail on the taxonomy term page'),
|
||||
'#description' => t('If enabled, the taxonomy term name is shown as the last breadcrumb item in the breadcrumb trail on the taxonomy term page.'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_show_current_term_term', FALSE),
|
||||
'#weight' => 35,
|
||||
);
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_include_node_title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show current node title in taxonomy breadcrumb trail'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_include_node_title', FALSE),
|
||||
'#description' => t("If enabled along with the taxonomy hierarchy option (above) and if viewing a node, the node's title will be shown as the last item in the breadcrumb trail."),
|
||||
'#weight' => 40,
|
||||
);
|
||||
|
||||
if (module_exists('views')) {
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_views'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use taxonomy-based breadcrumbs for views'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_views', FALSE),
|
||||
'#description' => t('If enabled, the view argument and/or the taxonomy structure of the nodes returned by views will be used to form the taxonomy breadcrumb trail.'),
|
||||
'#weight' => 50,
|
||||
);
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_result_nodes'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use the taxonomy of nodes returned by a view to create the taxonomy breadcrumb'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_result_nodes', FALSE),
|
||||
'#description' => t('If enabled, when a taxonomy-based view argument is not available the taxonomy from the first node returned by the view will be used. The view results will not be used if the taxonomy can be determined from the view argument.'),
|
||||
'#weight' => 55,
|
||||
);
|
||||
}
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_include_nodes'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Include or exclude taxonomy-based breadcrumbs for the following node types'),
|
||||
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_include_nodes', 0),
|
||||
'#options' => array(1 => t('Include'), 0 => t('Exclude')),
|
||||
'#weight' => 60,
|
||||
);
|
||||
|
||||
$cb_tax_types = (array) variable_get('custom_breadcrumbs_taxonomy_node_types', CUSTOM_BREADCRUMBS_TAXONOMY_NODE_TYPES_DEFAULT);
|
||||
$default = array();
|
||||
foreach ($cb_tax_types as $index => $value) {
|
||||
if ($value) {
|
||||
$default[] = $index;
|
||||
}
|
||||
}
|
||||
|
||||
$form['settings']['custom_breadcrumbs_taxonomy']['custom_breadcrumbs_taxonomy_node_types'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#multiple' => TRUE,
|
||||
'#title' => t('Node types to include or exclude'),
|
||||
'#default_value' => $default,
|
||||
'#options' => array_map('check_plain', node_get_types('names')),
|
||||
'#description' => t('A list of node types to include or exclude applying taxonomy-based breadcrumbs.'),
|
||||
'#weight' => 70,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
|
||||
// Load all custom breadcrumbs for this vid.
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_vocabulary', array('vid' => $form['vid']['#value']));
|
||||
$output = NULL;
|
||||
if (count($breadcrumbs) > 0) {
|
||||
$output = '<p>' . t('Custom breadcrumbs have been created for this vocabulary. Use the !link to add additional breadcrumbs. Or follow the links in the table below to edit or delete existing custom breadcrumbs.', array('!link' => l('Custom Breadcrumbs Administration Page', 'admin/build/custom_breadcrumbs'))) . '</p>';
|
||||
}
|
||||
// Show a table of custom breadcrumbs with links to the edit form.
|
||||
$output .= custom_breadcrumbs_simple_breadcrumb_table($breadcrumbs);
|
||||
$form['custom_breadcrumbs_taxonomy_vocabulary'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Custom Breadcrumbs for Taxonomy'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => -50,
|
||||
);
|
||||
$form['custom_breadcrumbs_taxonomy_vocabulary']['breadcrumb_table'] = array('#value' => $output, );
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_form_taxonomy_form_term_alter(&$form, &$form_state) {
|
||||
if (!(isset($_POST['op']) && $_POST['op'] == t('Delete')) || isset($_POST['confirm'])) {
|
||||
// Load all custom breadcrumbs for this tid.
|
||||
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_term', array('tid' => $form['tid']['#value']));
|
||||
$output = NULL;
|
||||
if (count($breadcrumbs) > 0) {
|
||||
$output = '<p>' . t('Custom breadcrumbs have been created for this term. Use the <a href="@link">Custom Breadcrumbs Administration Page</a> to add additional breadcrumbs. Or follow the links in the table below to edit or delete existing custom breadcrumbs.', array('@link' => url('admin/build/custom_breadcrumbs'))) . '</p>';
|
||||
}
|
||||
// Show a table of custom breadcrumbs with links to the edit form.
|
||||
$output .= custom_breadcrumbs_simple_breadcrumb_table($breadcrumbs);
|
||||
$form['custom_breadcrumbs_taxonomy_term'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Custom Breadcrumbs for Taxonomy'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => -50,
|
||||
);
|
||||
$form['custom_breadcrumbs_taxonomy_term']['breadcrumb_table'] = array('#value' => $output, );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_cb_node_form_table.
|
||||
*
|
||||
* @param $node
|
||||
* The node object being edited
|
||||
*
|
||||
* @return $breadcrumbs
|
||||
* an array of breadcrumb objects for taxonomy terms and vocabs matching the node
|
||||
* to be used in the custom_breadcrumbs fieldset on the node edit page
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_cb_node_form_table($node) {
|
||||
$breadcrumbs = array();
|
||||
if (_custom_breadcrumbs_taxonomy_allowed_node_type($node->type)) {
|
||||
if (!variable_get('custom_breadcrumbs_taxonomy_use_hierarchy', TRUE)) {
|
||||
// Check each term to see if it has a custom breadcrumb.
|
||||
$terms = taxonomy_node_get_terms($node);
|
||||
foreach ($terms as $term) {
|
||||
$more = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_term', array('tid' => $term->tid));
|
||||
if (!empty($more)) {
|
||||
$breadcrumbs = array_merge($breadcrumbs, $more);
|
||||
}
|
||||
}
|
||||
// Also look for a match on the taxonomy vocabulary.
|
||||
$vocabularies = taxonomy_get_vocabularies($node->type);
|
||||
foreach ($vocabularies as $vocabulary) {
|
||||
$more = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_taxonomy', 'custom_breadcrumbs_taxonomy_vocabulary', array('vid' => $vocabulary->vid));
|
||||
if (!empty($more)) {
|
||||
$breadcrumbs = array_merge($breadcrumbs, $more);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $breadcrumbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current node is one of the types listed on the advanced settings page.
|
||||
*
|
||||
* @param $nodetype
|
||||
* The node type being considered for a custom breadcrumb.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the node type is selected for a custom breadcrumbs taxonomy breadcrumb,
|
||||
* FALSE otherwise.
|
||||
*/
|
||||
function _custom_breadcrumbs_taxonomy_allowed_node_type($nodetype) {
|
||||
// If the node type IS IN the node types list and the list IS inclusive OR
|
||||
// If the node type IS NOT IN the node types list and the list IS NOT inclusive (e.g. exclusive)
|
||||
// THEN modify the breadcrumb trail.
|
||||
|
||||
$array_of_types = array_filter((array)variable_get('custom_breadcrumbs_taxonomy_node_types', CUSTOM_BREADCRUMBS_TAXONOMY_NODE_TYPES_DEFAULT));
|
||||
$in_list = in_array($nodetype, $array_of_types);
|
||||
$allowed = ($in_list == variable_get('custom_breadcrumbs_taxonomy_include_nodes', 0));
|
||||
return $allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_enable() {
|
||||
// Sets weight of custom_breadcrumbs_taxonomy to be greater than taxonomy, views, and custom_breadcrumbs.
|
||||
$max_weight = custom_breadcrumbs_taxonomy_minimum_module_weight();
|
||||
$current_weight = _custom_breadcrumbs_get_module_weight(array('custom_breadcrumbs_taxonomy'));
|
||||
if ($current_weight < $max_weight) {
|
||||
drupal_set_message(t('Increasing the weight of custom_breadcrumbs_taxonomy for use with other modules.'));
|
||||
db_query("UPDATE {system} SET weight = %d WHERE name = 'custom_breadcrumbs_taxonomy'", $max_weight);
|
||||
variable_set('menu_rebuild_needed', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_minimum_module_weight().
|
||||
*
|
||||
* @see custom_breadcrumbs_admin_settings_submit().
|
||||
*/
|
||||
function custom_breadcrumbs_taxonomy_minimum_module_weight() {
|
||||
$modules = array('taxonomy', 'views', 'page_manager', 'custom_breadcrumbs', 'i18ntaxonomy');
|
||||
$weights = _custom_breadcrumbs_get_module_weight($modules);
|
||||
$max_weight = array_pop($weights);
|
||||
return $max_weight + 1;
|
||||
}
|
Reference in a new issue