how to use session favorites
rzo - December 9, 2008 - 16:12
| Project: | Session Favorites |
| Version: | 6.x-1.4 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Great module, i'm wondering if maybe you could add some practical examples to the documentation. Will be great if can add how you accomplish the integration in the demo page.
Thanks

#1
Hey rzo.
It's been awhile since I did the state fair site pointed to as a demo for this module, but I'll do my best to get you started.
All of the non-standard behavior on that site was accomplished by overriding the themeable functions for the session favorites module. For example, to get the custom links, we used this function in our template.php file:
<?php
/**
* Override the session favorites page
*/
function phptemplate_session_favorites_list($list) {
$own_list = session_favorites_viewing_own_list();
foreach ($list as $node) {
if ($own_list) {
// add a remove link
$remove_link = ' ' . l('remove', variable_get('session_favorites_path', 'session-favorites') . '/remove/' . $node->nid, NULL, drupal_get_destination());
}
$formatted[] = l($node->title, 'node/' . $node->nid) . $remove_link;
}
$header = $own_list ? variable_get('session_favorites_header', '') : variable_get('session_favorites_header_other', '');
$footer = $own_list ? variable_get('session_favorites_footer', '') : variable_get('session_favorites_footer_other', '');
if (user_access('administer session favorites')) {
$footer .= '<div class="admin-edit-link">' . l(t('Edit header/footer'), 'admin/settings/session-favorites') . '</div>';
}
if (empty($formatted)) {
$content = $own_list
? variable_get('session_favorites_empty', t("You haven't added any items to your favorites list"))
: variable_get('session_favorites_empty_other', t('This list does not have any entries'));
}
else {
foreach ($list as $node) {
$content .= node_view($node);
}
}
if (module_exists('session_favorites_email') && session_favorites_viewing_own_list()) {
$email_link = theme('session_favorites_email_link');
}
return $email_link . $header . $content . $footer;
}
to generate the custom listing of favorites.
?>
and also (since this site was in Drupal 5) we had this in our phptemplate_preprocess_page() function:
<?phpif (module_exists('session_favorites') && session_favorites_available()) {
// Can't Miss functionality
$favs = count(session_favorites_get_list());
$vars['cant_miss_list'] = l(t('My Can\'t-Miss List'),variable_get('session_favorites_path', 'session-favorites')) . t(' (@items added)', array('@items' => $favs . ' ' . format_plural($favs, 'item', 'items')));
}
?>
which created a the count variable for the header (to be placed in the page.tpl.php file).
Finally, in the phptemplate_preprocess_node() function:
<?php// Can't Miss functionality
if (module_exists('session_favorites') && session_favorites_available()) {
if (session_favorites_node_check($vars['node']->nid)) {
// alread in favorites
$link = t('In Can\'t Miss list (<a href="!url" title="Remove from my Can\'t Miss List" class="cant-miss-link">remove</a>)', array('!url' => url(variable_get('session_favorites_path', 'session-favorites') . '/remove/' . $vars['node']->nid, drupal_get_destination())));
}
else {
$link = l(t('Add to can\'t miss list'), variable_get('session_favorites_path', 'session-favorites') . '/add/' . $vars['node']->nid, array('title' => t('Add @title to my can\'t miss list', array('@title' => $vars['node']->title)), 'class' => 'cant-miss-add-link'), drupal_get_destination());
}
$vars['cant_miss_link'] = $link;
}
?>
This allowed the add/remove link to be placed outside of the normal location for links associated with a node.
Hope that helps.
#2
Thanks man for your help, those snippets of code were really useful, awesome module. Thanks again!!!