Monday, October 27, 2008

jQuery Image Gallery, jQuery Slideshow

The Galleria module for jQuery makes a really great jQuery Image Gallery. Added some tweaks to it, and now I've got a jQuery Image Gallery and Slideshow. With features such as pause on hover, and a contact sheet.

Friday, October 10, 2008

Theme Drupal Search Results

I had the most awful time trying to theme the drupal search results page and remove the silly "node type", "author", "date" and "extra" info from the search results.

Initially I tried the easy route which was to copy modules/search/search-result.tpl.php into my theme and then in the themes template.php file remove the search-info div. Because that's the info I didn't want to show up.

Didn't work. Worked only for /search/node. Failed when going to /search/node/some%20search%20term.

Finally was able to get it working by implementing hook_prepocess_search_result, and making sure the $info array didn't have anything.


/**
* Implement hook_preprocess_search_result()
*/
function phptemplate_preprocess_search_result(&$variables) {
$result = $variables['result'];
$variables['url'] = check_url($result['link']);
$variables['title'] = check_plain($result['title']);

$info = array();
/* HIDE THIS FROM END USER
if (!empty($result['type'])) {
$info['type'] = check_plain($result['type']);
}
if (!empty($result['user'])) {
$info['user'] = $result['user'];
}
if (!empty($result['date'])) {
$info['date'] = format_date($result['date'], 'small');
}
if (isset($result['extra']) && is_array($result['extra'])) {
$info = array_merge($info, $result['extra']);
}
*/
// Check for existence. User search does not include snippets.
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
// Provide separated and grouped meta information..
$variables['info_split'] = $info;
$variables['info'] = implode(' - ', $info);
// Provide alternate search result template.
$variables['template_files'][] = 'search-result-'. $variables['type'];
}

With this gem in my hook_theme implementation

'search_result' => array(
'arguments' => array('result' => NULL, 'type' => NULL),
'template' => 'search-result',
'path' => drupal_get_path('module', 'search')
)


Monday, October 06, 2008

Disable the Drupal User Contact Form

The best way I've found to disable the user "contact form", is to hook_menu_alter and remove the 'contact' fieldset from the user profile form itself.


function modulename_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_profile_form':
unset($form['contact']);
break;
...