You are here

function contact_update_6200 in Contact 6.2

Migrate contact information to a block.

File

./contact.install, line 93
Install, update and uninstall functions for the contact module.

Code

function contact_update_6200() {
  $themes_with_blocks = array();
  $query = db_query("SELECT DISTINCT(s.name) FROM {system} s INNER JOIN {blocks} b ON s.name = b.theme WHERE s.type = 'theme' GROUP by s.name");
  while ($theme = db_result($query)) {
    $themes_with_blocks[] = $theme;
  }

  // Migrate contact form information.
  $default_format = variable_get('filter_default_format', 1);
  if ($contact_help = variable_get('contact_form_information', '')) {
    $block = array(
      'body' => $contact_help,
      'info' => 'Contact page help',
      'format' => $default_format,
    );
    drupal_write_record('boxes', $block);
    foreach ($themes_with_blocks as $theme) {

      // Add contact help block for themes, which had blocks.
      $theme_block = array(
        'module' => 'block',
        'delta' => $block['bid'],
        'theme' => $theme,
        'status' => 1,
        'weight' => 5,
        'region' => '',
        'visibility' => 1,
        'pages' => 'contact',
        'cache' => -1,
      );
      drupal_write_record('blocks', $theme_block);
    }
    drupal_set_message('The contact form information setting was migrated to <a href="' . url('admin/build/block/configure/block/' . $block['bid']) . '">a custom block</a> and set up to only show on the site-wide contact page. It has not yet been assigned a region. The block was set to use the default text format, which might differ from the HTML based format used before. Check the block and ensure that the output is right.');
  }
  variable_del('contact_form_information');
  return array();
}