Node Gallery Tricks & Customizations
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
This page is for customizations to the module and ways to do things beyond the basics. If you have a helpful trick for node gallery, this is the place to make it known.
Note: These tricks are not supported in the node gallery issue que, but a well worded title in the Drupal forum might provide some help.
Additional Tokens for parent_node_gallery_term(taxonomy) and it's path
Case: I am using node galleries with taxonomy. Each gallery belongs to one term and I wanted to have some custom breadcrumbs using 4 additional tokens:
[parent-node-gallery-term] The name of the term of the parent Gallery.
[parent-node-gallery-term-raw] Unfiltered name of the term of the parent Gallery.
[parent-node-gallery-title] The path of the term of the parent Gallery.
[parent-node-gallery-term-path-raw] Unfiltered path of the term of the parent Gallery.
Note: The only limit to this is that it will only use one taxonomy term, not multiple terms. If more than one term is selected, the first taxonomy term will be used.
Instructions: Keep a backup of the original file just in case. Copy the following code to a text file and name it node_gallery.token.inc
. Replace the original file in the node gallery folder with the new one. This code includes the existing 4 tokens that come in the node gallery package, so you won't loose anything. This does not require any installation, just clear the cache.
Thanks to wapnik for this customization, enjoy!
<?php
// $Id: node_gallery.token.inc,v custom 2009/29/09 wapnik Exp $
/**
* @file
* Token module support for the Node Gallery module.
*/
/**
* Implementation of hook_token_list().
*/
function node_gallery_token_list($type = 'all') {
$tokens = array();
if ($type == 'node' || $type == 'all') {
$tokens['node']['parent-node-gallery-path'] = t('The path of the parent Gallery.');
$tokens['node']['parent-node-gallery-path-raw'] = t('Unfiltered path of the parent Gallery. WARNING - raw user input.');
$tokens['node']['parent-node-gallery-title'] = t('The title of the parent Gallery.');
$tokens['node']['parent-node-gallery-title-raw'] = t('Unfiltered title of the parent Gallery. WARNING - raw user input.');
$tokens['node']['parent-node-gallery-term'] = t('The name of the term of the parent Gallery.');
$tokens['node']['parent-node-gallery-term-raw'] = t('Unfiltered name of the term of the parent Gallery.');
$tokens['node']['parent-node-gallery-term-path'] = t('The path of the term of the parent Gallery.');
$tokens['node']['parent-node-gallery-term-path-raw'] = t('Unfiltered path of the term of the parent Gallery.');
return $tokens;
}
}
/**
* Implementation of hook_token_values().
*/
function node_gallery_token_values($type, $object = NULL, $options = array()) {
$tokens = array();
if ($type == 'node' && in_array($object->type, (array)node_gallery_get_types('image'))) {
if (empty($object->gid)) {
$object->gid = db_result(db_query("SELECT gid FROM {node_galleries} WHERE nid = %d", $object->nid));
}
if ($object->gid) {
$parent_path = 'node/'. $object->gid;
if (module_exists('path')) {
$parent_path = drupal_get_path_alias($parent_path);
}
// Load up the title of the parent
$parent_title = db_result(db_query("SELECT title FROM {node} WHERE nid = '". $object->gid ."'"));
// Load up the name of the term of the parent and it's path
$parent_terms = taxonomy_node_get_terms(node_load($object->gid));
foreach ($parent_terms as $parent_term) {
$parent_term = $parent_term->name;
$parent_term_path = 'taxonomy/term/'. $parent_term->tid;
if (module_exists('path')) {
$parent_term_path = drupal_get_path_alias($parent_term_path);
}
break;
}
$tokens['parent-node-gallery-path'] = decode_entities(check_plain($parent_path));
$tokens['parent-node-gallery-path-raw'] = $parent_path;
$tokens['parent-node-gallery-title'] = decode_entities(check_plain($parent_title));
$tokens['parent-node-gallery-title-raw'] = $parent_title;
$tokens['parent-node-gallery-term'] = decode_entities(check_plain($parent_term));
$tokens['parent-node-gallery-term-raw'] = $parent_term;
$tokens['parent-node-gallery-term-path'] = decode_entities(check_plain($parent_term_path));
$tokens['parent-node-gallery-term-path-raw'] = $parent_term_path;
}
return $tokens;
}
}
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion