Some Drupal 7 porting tips

Submitted by nk on Fri, 2010-01-22 08:32.
  • UPDATE/INSERT often can be updated to a single db_merge.
  • Don't forget to ->execute() your db_select/db_insert/etc
  • Themes can have many variables and you might want to do
    function theme_fivestar_preview($variables) {
      $theme_definition = fivestar_theme();
      foreach ($theme_definition['fivestar_preview']['arguments'] as $key => $default) {
        $$key = $variables[$key];
      }

    Edit: merlinofchaos suggests simply extract($variables, EXTR_SKIP); because that's what templates do.
Submitted by dereine (not verified) on Fri, 2010-01-22 14:07.

The signature of hook_theme is not as easy :( hook_theme($existing, $type, $theme, $path)

I would use

<?php
  $hooks
= theme_get_registry();
  foreach (
$hooks['foo']['arguments'] as $key => $default) {
    $
$key = $variables[$key];
  }
?>

User login