Turning off Drupal 7 admin toolbar


Drupal 7 has this nice lovely toolbar at the top of admin pages, right?

It's a great idea. It adds easy access to important parts of the website. It's a great improvement from the standard administration workflow.

It also doesn't provide the delightful dropdown menus of the Administration menu toolbar. I don't like the Drupal 7 admin tool bar. Yes, it stays put (position:fixed), but it's the bastard half brother of what I'm used to having.

The easiest way to disable the default admin toolbar and enable the admin_menu toolbar?

After installing the Administration menu, in admin/people/permissions:

1. Enable Administration menu » Access administration menu for the role you want (I updated the Administrator role).

2. Disable Toolbar » Use the administration toolbar for the role you want (I updated the Administrator role).

No code modification. Yay!

Get the bundle of a Drupal 7 entity


Drupal 7's EntityAPI allows entities to be divided into different "bundles" based on their properties. Unfortunately, there's no way to easily determine what bundle a particular concrete entity object belongs to. This helper function appears to work for the entity types that ship with core.

function _entity_get_bundle($entity, $entity_type) {
  $info = entity_get_info($entity_type);
  if (empty($info['entity keys']['bundle'])) {
    return $entity_type;
  } else {
    return $entity->{$info['entity keys']['bundle']};

Drupal 7 Multiviews Error fix


Installing Drupal 7 for a project, received a 500 Server configuration error.

Looking in the Apache error log, I saw the error:

[Wed Jan 12 19:40:24 2011] [alert] [client xxx.xxx.xxx.xxx] /var/www/httpdocs/.htaccess: Option Multiviews not allowed here

Turns out, in the apache2 config file, the following is not sufficient in the Directory section:

AllowOverride Options FileInfo AuthConfig Limit Indexes

In particular, the MultiViews option is needed:

AllowOverride Options=All,MultiViews FileInfo AuthConfig Limit Indexes