You are here

function featured_content_add_block_form_submit in Featured Content 6

Same name and namespace in other branches
  1. 6.2 featured_content.admin.inc \featured_content_add_block_form_submit()
  2. 7.2 featured_content.admin.inc \featured_content_add_block_form_submit()
  3. 7 featured_content.admin.inc \featured_content_add_block_form_submit()

Save new block.

File

./featured_content.admin.inc, line 19
Provides infrequently used functions for featured content module.

Code

function featured_content_add_block_form_submit($form, &$form_state) {

  // determine delta of new block
  $block_ids = variable_get('featured_content_block_ids', array());
  $delta = empty($block_ids) ? 1 : max($block_ids) + 1;

  // save new array of blocks ids
  $block_ids[] = $delta;
  variable_set('featured_content_block_ids', $block_ids);

  // save block configuration
  featured_content_save($delta, $form_state['values']);

  // run 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, cache) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d)", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $theme->name, 0, 0, $delta, BLOCK_NO_CACHE);
    }
  }
  foreach (array_filter($form_state['values']['roles']) as $rid) {
    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
  }
  drupal_set_message(t('The Featured Content Block has been created.'));
  cache_clear_all();
  $form_state['redirect'] = 'admin/build/block';
  return;
}