Drupal 6 gotchas / bugs

Notes about Drupal 6 gotchas / bugs.

Index

Permissions

Granting permissions to ‘anonymous user’ does not grant them to an ‘authenticated user’. Granting permission to an ‘authenticated user’ grants permission for all other roles, because a user is always added to ‘authenticated user’.

Required checkbox not required

Normally when a form field is marked as required then Drupal automatically labels the field as required (with an asterix) and performs validation. This doesn’t seem to happen with checkboxes. The workaround is to add the asterix to the title and write a custom validation function, as done by the f3 Anti Spam Contact Form module:

/**
 * Implements hook_form_alter() to add a checkbox for basic spam control.
 */
function f3_anti_spam_contact_form_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'contact_mail_page') {
    $form['submit']['#weight'] = 2; // Set the weight of the submit button so we can position the checkbox.
    $form['human'] = array(
      '#type' => 'checkbox',
      // We add the asterix markup to the title as there seems to be a bug in Drupal that prevents it
      // being added automatically as it would if it were any other type of field.
      '#title' => t('Are you human? <span class="form-required" title="This field is required.">*</span>'),
      '#description' => t("This is a basic mechanism to prevent spam. Please check the box."),
      '#required' => TRUE,
      '#element_validate' => array('is_human_checked'),
      '#weight' => 1
    );
  }
}

/**
 * We need a validation function as there seems to be a bug in Drupal that prevents it
 * auto validating required checkboxes as it would if it were any other type of field.
 */
function is_human_checked($element, &$form_state) {
  if (empty($element['#value'])) {
    form_error($element, t("Please check the box to tell use you're human!"));
  }
}

ImageCache

ImageCache always scales

If you have ImageCache set to scale images to particular dimensions, this will occur even if the original source image is already at the correct dimensions. Presumably the same applies to resize and other operations.

ImageCache scaling destroys GIFs

ImageCache scaling will destroy GIF animations.

Missing ImageCache images

When you add an ImageCache preset, remember to update the permissions to allow roles to view it.

Administer -> User management -> Permissions, ‘imagecache module’ section, ‘view imagecache [preset_name]’.

Themed views template doesn’t get variables

If you try to theme a Views template by copying it from sites/all/modules/views/themes/[template] to sites/all/themes/[theme]/templates/[template], the variables in the template will not be instantiated and you’ll get an error like the following:

warning: Invalid argument supplied for foreach() in /home/bn/f3/clients/finn_guild/dev/website/drupal/sites/all/themes/finnguild/templates/block-views-sidebar_adverts-block_1.tpl.php on line 13.

Solution: Instead of using the block id as the name of the template, use the view’s template name with the view name and display name (both optional of course):

views-view-unformatted--sidebar_adverts--block.tpl.php instead of block-views-sidebar_adverts-block_1.tpl.php.

See Views 2 theming

Template suggestions ignored unless “parent” template exists

If you are trying to theme a specific block, e.g. block-block-3.tpl.php, it will be ignored unless block.tpl.php also exists!

Module translation .po files missing after upgrade

Problem: After Drupal upgrade, modules are missing their translations directory at [site_root]/modules/[module]/translations (which should contain the .po translation files).

Solution: This isn’t a bug and you don’t need to do anything to fix!…

When you install a translation you first download and extract the translation files. This creates the translations directories for the core modules, each of which will contain .po files that hold the translations themselves. You then import the translations into the database via the admin UI.

Hence, after upgrade, the core modules will not have the translations directories (unless you download and extract them again) but the database will already hold the translations.

The primary links ($primary_links) can be themed via the them function in your page template, which allows you to add markup around the menu. E.g. Zen does the following:

<?php if ($primary_links || $navigation): ?>
  <div id="navigation"><div class="section clearfix">

    <?php print theme(array('links__system_main_menu', 'links'), $primary_links,
      array(
        'id' => 'main-menu',
        'class' => 'links clearfix',
      ),
      array(
        'text' => t('Main menu'),
        'level' => 'h2',
        'class' => 'element-invisible',
      ));
    ?>

    <?php print $navigation; ?>

  </div></div> <!-- /.section, /#navigation -->
<?php endif; ?>

However, the Primary Links menu is also available as a block, though for Zen it’s not enabled because the page template outputs the primary links anyway. For consistency, it would be good if you could control the menu positioning via its block and theme it without having to rely on code in the page template.

This however does not seem possible. You can use THEME_menu_tree, but the modifications will apply to all menus as there’s no menu ID supplied. Hence, you can not theme particular menus that are in a block, so you’re left with a useless Primary Links block.

Breadcrumbs

Breadcrumbs are sourced from the taxonomy terms associated with a node, so you’ll have to roll your own if you want it to reflect menu hierarchy.

Use the Menu Breadcrumb module to have breadcrumbs sourced from menu hierarchy (admin breadcrumbs still work).

Adding unique IDs to menu ULs

I can’t find a way to add unique IDs to the menu ULs, because theme_menu_tree, responsible for surrounding the menu item markup in an UL, doesn’t allow you to query menu id - it simply takes the item markup as argument.

View menu items

Views (at least page views) provide config so you can add them to a menu. However, they only allow you to create an item at the top level of a menu and the functionality seems buggy in that the menu item sometimes disappears when you later edit the view.

Better to give the view a page and create a menu item via Administer -> Site building -> Menus.

You can have language-specific items in a language-neutral menu, but not the other way around. E.g. if you add english and finnish items to a neutral menu everything work fine (menu breadcrumbs, f3 custom section menu, etc), but if you add a neutral item to both a finnish and an english menu then Drupal will only use the first menu item it finds hence the menu in one of the languages will not show correctly.

Core patch to menu.inc required to overcome. See Active trail isn’t set on all menu items pointing to the current path.

Last modified: 16/11/2011 Tags: ,

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top