You are here

function i18nblocks_save in Internationalization 5

Same name and namespace in other branches
  1. 5.3 i18nblocks/i18nblocks.module \i18nblocks_save()
  2. 5.2 i18nblocks/i18nblocks.module \i18nblocks_save()
  3. 6 i18nblocks/i18nblocks.module \i18nblocks_save()
4 calls to i18nblocks_save()
i18nblocks_block in i18nblocks/i18nblocks.module
Implementation of hook_block()
i18nblocks_form_submit in i18nblocks/i18nblocks.module
i18nblocks_nodeapi in i18nblocks/i18nblocks.module
Implementation of hook_nodeapi
i18nblocks_update_1 in i18nblocks/i18nblocks.install
Update: move old variable to new tables

File

i18nblocks/i18nblocks.module, line 298

Code

function i18nblocks_save($edit, $delta = NULL) {
  $delta = isset($edit['delta']) && $edit['delta'] ? $edit['delta'] : $delta;
  if ($delta) {
    db_query("UPDATE {i18n_blocks} SET info = '%s', type = '%s' WHERE delta = '%s'", $edit['info'], $edit['type'], $delta);
    db_query("DELETE FROM {i18n_blocks_i18n} WHERE bid = %d", $delta);
  }
  else {

    // New block, return delta value
    $edit['delta'] = $delta = db_next_id('{i18n_blocks}_delta');
    if ($edit['info'] == t('New multilingual block') || !$edit['info']) {
      $edit['info'] = t('Multilingual block !number', array(
        '!number' => $delta,
      ));
    }
    db_query("INSERT INTO {i18n_blocks}(delta, info, type) VALUES('%d', '%s', '%s')", $delta, $edit['info'], $edit['type']);
    drupal_set_message(t("Created new block '%name'", array(
      '%name' => $edit['info'],
    )));
  }

  // Save language blocks
  foreach ($edit['i18nblocks'] as $lang => $path) {
    if ($path) {
      list($module, $gamma) = explode(':', $path);
      db_query("INSERT INTO {i18n_blocks_i18n}(bid, language, module, delta) VALUES(%d, '%s', '%s', '%s')", $delta, $lang, $module, $gamma);
    }
  }
  return $edit;
}