Drupal Module Notes

Below is a list of notes that were written down due to a few problems in certain modules in Drupal. They are all based on Drupal 5.x's module set, not 6.x.

=BUG=

Please note there's a bug especially with this page that duplicates content when you save.. It's mentioned here. I'm trying to fix it.

Here are a few tips to save someone the trouble with innitial configs, modifications, and mods.

please try and keep it as alphabetically ordered as possible.

=General Configs=

Anything in general

Remove new 'welcome to your new install' message
One way of doing it is by setting that $output to null.

Edit modules/node.module

the else lines between 2386 and 2404

delete all the lines inside and replace $output = ' '. $default_message .' '; with $output = '';

An alternative method is to keep it all there, and just remove the word 'Drupal' from the content.

Using Drupal functions and database with your own files
Some times you need to add some files to your system to do a special thing. So to use all the utilities that drupal gave to it's files just add these two lines at the top of your file: include_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

CMS Customer Admin Rights
When the project is complete, do NOT give the customer the full admin user rights. Instead, create an administrator account for him with slightly less rights. Here are the settings you should take a note of:

Having a different homepage
If your homepage has a different design to the rest of the website, the easiest thing to do is to go to your theme folder, and edit template.php (create it if it's not there). look for the following function

function _phptemplate_variables($hook, $vars = array) { switch ($hook) { // Send a new variable, $has_terms, to see wether the current node has any terms case 'node': if(count(taxonomy_node_get_terms($vars['node']->nid))) $vars['has_terms'] = TRUE; else $vars['has_terms'] = FALSE; break; }   return $vars; }

Append the following case into it case 'page': if ($vars['is_front'] ) { $vars['template_file'] = 'page-index'; } break;

Then create a page-index.tpl.php in your theme folder, and add whatever you want in there. That will be your homepage page.

Creating your own regions for your template
If you want to create your own regions in your template to print the blocks into them, override the current ones with the following function in template.php, putting the name of your theme in the function name. For example, if my theme is called fishtheme,

/** * Declare the available regions implemented by this engine. * In other words, override the regions to create new ones. * * @return *   An array of regions. The first array element will be used as the default region for themes. *   Each array element takes the format: variable_name => t('human readable name') */ function fishtheme_regions { return array(      // The default ones.       'left' => t('left sidebar'),       'right' => t('right sidebar'),       'content_top' => t('content top'),       'content_bottom' => t('content bottom'),       'header' => t('header'),       'footer' => t('footer'),

// your own ones 'topLeftMenu' => t('Top Left Menu'), 'topMenu' => t('Top Menu'), 'bottomMenu' => t('Bottom Menu'), 'translationMenu' => t('Translation Menu'), 'exampleTest' => t('any example test') ); }

In admin/build/blocks, just assign the block to your new region, then in your template,  to print the top left menu, etc..

How to use RTL CSS
First off all you have to install the i18 module and after you activate it go to admin/settings/locale or admin/settings/i18n/language then click on RTL for the language you want.

After that go to the theme you are using and add these lines of code to template.tpl.php // to switch the theme based on the language if (module_invoke('i18n', 'language_rtl')) { drupal_add_css(path_to_theme .'/style-rtl.css', 'theme'); } else { drupal_add_css(path_to_theme .'/style.css', 'theme'); }

Then start adding your styles to style-rtl.css which is in the same theme you are using.

=Specific Module Configurations=

Anything module related. Please try to keep it arranged in alphabetical order

Advertisement Module
This is a big one..

Flash ads support
Flash ad support is experimental, but the last few builds seem to work 90%.

This thread is the most up to date and most accurate. Skip down to comment #57, and grab the zip file there. This worked for me. There's just a small problem with the destination path if a user clicks on the image, but i think this is solvable by embedding the links within the flash itself. The only problem is that you can't log the click in statistics i think.

Group name too long bug
This bug report describes that if you have long group names, you'll get a mysql warning data too long for column 'delta'....

Backup & Migrate
Very useful module. Use it with poormanscron to create scheduled backups of the database. 2 problems though with the current dev branch (as of today - 20071128)

1) move the directory out of files/ dir,

around line 940, look for the _backup_migrate_get_save_path function, and edit the $dir line from

$dir = file_directory_path ."/backup_migrate"; to $dir = variable_get('bk_directory_path', 'bk');

This will change it to a bk folder in the root.

2) When changing the php date format, it doesn't take effect with the Scheduled tasks.. I'll solve it shortly.

Comments module
If you want to remove the title from comments, not only do you have to disable it from the comments settings in admin, but also get rid of the print $title in comment.tpl.php

If you want to change the date format to something like "Posted XX minutes ago", follow these steps.

Help
This is more of a development module. Make sure to disable it first from the modules page, then delete it from modules/help.module.

Fckeditor
NOTE: I no longer use FCKEditor. I switched to TinyMCE. It's more lightweight and has better support for multiple browsers.

Feedback
If you want to add your feedback form into a block, create a new block, and add the following code to the body (source, input style: php)



FiveStar
Fivestar 1.8 breaks Send module. Disable it from the Send node until fixed

http://drupal.org/node/127519#comment-660901

CCK
This is a drupal 5.x module. It is an alternative for flexinode in drupal 4.7

how to add image field with thumbnail

I18n and Translations
Note: Before you start, read the following comparison charts to see which module suits you

http://www.developmentseed.org/blog/internationalization/comparison_chart

http://www.developmentseed.org/blog/i18n/computer_aided_translation

Translating Menu Titles
Have you tried translating the whole website, and it worked apart from the menu-titles? Did #drupal-support say you can't translate them because they are user data entered? well HA!!..

To fix it, edit includes/menu.inc ~line 701

Replace function theme_menu_item_link($item, $link_item) { return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array); }

with

function theme_menu_item_link($item, $link_item) { return l(t($item['title']), $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array); }

Having a theme for each language, RTL/LTR
NOTE: This is only for drupal 4.7. It wont work on 5.x

Instead of having two different themes, just use this override to use different CSS files. One for each language you have.

Add the following function to themes//template.php

/** * Override languages to have two CSS files * */ function phptemplate_stylesheet_import($path, $media = 'all') { // May be it's better to add a variable isRTL to locales_meta // table so as not to hardcode the languages in the code $rtl = array('ar', 'he'); // There are a couple or so more if (in_array(locale_initialize, $rtl)) { if (file_exists(path_to_theme. '/drupal_RTL.css')) { theme_add_style(path_to_theme . '/drupal_RTL.css', $media); }		if (file_exists(path_to_theme. '/RTL.css')) { theme_add_style(path_to_theme . '/RTL.css', $media); }	}	return theme_stylesheet_import($path, $media); }

Block Titles
To make the title of a block translated you have to do the following in block.module line 131:

Replace $data['subject'] = check_plain($block->title);

with

$data['subject'] = check_plain(t($block->title));

Enabling Language Switcher without flags
If you need the language switcher bar to switch between languages, Just enable it in the blocks.

To remove the "Languages:" text, add to the block name.

Finally, If you want the words translated, also If you don't want the flags to appear, override the function theme_i18n_link with the following in your template.tpl.php file:

 'active') : NULL; // $output .= l(theme('i18n_language_icon', $lang), $target, $attributes, NULL, NULL, FALSE, TRUE); // $output .= $separator; // $output .= l($text, $target, $attributes, NULL, NULL, FALSE, TRUE); $output .= l(t($text), $target, $attributes, NULL, NULL, FALSE, TRUE); $output .= ' '; return $output; } ?>

Alternatively, you can give the user a choice in the menu with the following code in i180n.module

Add the following into function i18n_admin_settings $form['i18n_format'] = array(   '#type' => 'radios',    '#title' => t('Display language icons?'),    '#default_value' => variable_get('i18n_format', 'text'),    '#options' => array( 'text' => t('Language Only'), 'textandicon' => t('Language Plus Icon'), 'icon' => t('Icon Only')) );

And around line 650, replace the theme_i18n_link function with the following, function theme_i18n_link($text, $target, $lang, $query= NULL, $fragment = NULL){ $output = ' '; $attributes = ($lang == i18n_get_lang) ? array('class' => 'active') : NULL; switch(variable_get('i18n_format', 'text')) { case 'text': $output .= l($text, $target, $attributes, $query, $fragment, FALSE, TRUE); break; case 'textandicon': $output .= l(theme('i18n_language_icon', $lang), $target, $attributes, $query, $fragment, FALSE, TRUE); $output .= " "; $output .= l($text, $target, $attributes, $query, $fragment, FALSE, TRUE); break; case 'icon': $output .= l(theme('i18n_language_icon', $lang), $target, $attributes, $query, $fragment, FALSE, TRUE); break; } $output .= ' '; return $output; }

Image name problem
there is a problem that was faced in uploading images that have a space in its name, so a good solution is to add this line of code: $file['filename'] = str_replace(' ', '_', $file['filename']); at the beginning of imagefield_file_insert($node, &$file, $field) function in the imagefield module

Menu Module
If you want to keep the menus as-is, but have some that you can't click on, you need to override the menu_item_link function. Add the following to your template.php

'. $item['title'] .' '; } else { return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array, isset($item['query']) ? $item['query'] : NULL); } } ?>

Any menu item whose path is will now become a span rather than a link. Note that because it's not a link you can't click on it, so you can't access sub-menu items unless the no-link menu item has the "Expand" checkbox checked so that its children are always visible. If you need to have access to the sub-menu items for things like dropdown/flyout menus, try using the JavaScript version of this snippet.

TinyMCE + No Teasers
There's a bug in TinyMCE that breaks the teasers, displaying nothing.

Note: When using TinyMCE with i18n, be sure to edit the TMCE settings to let it work on all languages as so,

Administer -> TinyMCE -> Visibility

change node/* user/* comment/* to node/* user/* comment/* ar/node/* ar/user/* ar/comment/* en/node/* en/user/* en/comment/*

And add any other language you use as well to the list.