You are here

function menu_block_add_block_form_submit in Menu Block 5.2

Same name and namespace in other branches
  1. 6.2 menu_block.admin.inc \menu_block_add_block_form_submit()
  2. 7.3 menu_block.admin.inc \menu_block_add_block_form_submit()
  3. 7.2 menu_block.admin.inc \menu_block_add_block_form_submit()

Save the new menu block.

File

./menu_block.admin.inc, line 19
Provides infrequently used functions for menu_block.

Code

function menu_block_add_block_form_submit($form_id, $form_values) {

  // Determine the delta of the new block.
  $block_ids = variable_get('menu_block_ids', array());
  $delta = empty($block_ids) ? 1 : max($block_ids) + 1;

  // Save the new array of blocks IDs.
  $block_ids[] = $delta;
  variable_set('menu_block_ids', $block_ids);

  // Save the block configuration.
  _menu_block_block_save($delta, $form_values);

  // Run the normal new block submission (borrowed from block_add_block_form_submit).
  foreach (list_themes() as $key => $theme) {
    if ($theme->status) {
      db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d)", $form_values['visibility'], trim($form_values['pages']), $form_values['custom'], $form_values['title'], $form_values['module'], $theme->name, 0, 0, $delta);
    }
  }
  foreach (array_filter($form_values['roles']) as $rid) {
    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $delta);
  }
  drupal_set_message(t('The block has been created.'));
  cache_clear_all();
  return 'admin/build/block';
}