You are here

function twitter_block_add_block_form_submit in Twitter Block 7.2

Same name and namespace in other branches
  1. 7 twitter_block.admin.inc \twitter_block_add_block_form_submit()

Form submission handler for twitter_block_add_block_form().

Saves the new custom Twitter block.

See also

twitter_block_add_block_form()

twitter_block_add_block_form_validate()

1 string reference to 'twitter_block_add_block_form_submit'
twitter_block_add_block_form in ./twitter_block.admin.inc
Form constructor for the add block form.

File

./twitter_block.admin.inc, line 81
Admin page callbacks for the Twitter Block module.

Code

function twitter_block_add_block_form_submit($form, &$form_state) {

  // The serialized 'data' column contains the timeline settings.
  $data = array(
    'theme' => $form_state['values']['theme'],
    'link_color' => $form_state['values']['link_color'],
    'width' => $form_state['values']['width'],
    'height' => $form_state['values']['height'],
    'chrome' => $form_state['values']['chrome'],
    'border_color' => $form_state['values']['border_color'],
    'language' => $form_state['values']['language'],
    'tweet_limit' => $form_state['values']['tweet_limit'],
    'related' => $form_state['values']['related'],
    'polite' => $form_state['values']['polite'],
  );

  // Save the block configuration.
  $delta = db_insert('twitter_block')
    ->fields(array(
    'info' => $form_state['values']['info'],
    'widget_id' => $form_state['values']['widget_id'],
    'username' => $form_state['values']['username'],
    'data' => serialize($data),
  ))
    ->execute();

  // Store block delta to allow other modules to work with new block.
  $form_state['values']['delta'] = $delta;

  // Run the normal new block submission (borrowed from block_add_block_form_submit).
  $query = db_insert('block')
    ->fields(array(
    'visibility',
    'pages',
    'custom',
    'title',
    'module',
    'theme',
    'status',
    'weight',
    'delta',
    'cache',
  ));
  foreach (list_themes() as $key => $theme) {
    if ($theme->status) {
      $query
        ->values(array(
        'visibility' => (int) $form_state['values']['visibility'],
        'pages' => trim($form_state['values']['pages']),
        'custom' => (int) $form_state['values']['custom'],
        'title' => $form_state['values']['title'],
        'module' => $form_state['values']['module'],
        'theme' => $theme->name,
        'status' => 0,
        'weight' => 0,
        'delta' => $delta,
        'cache' => DRUPAL_NO_CACHE,
      ));
    }
  }
  $query
    ->execute();
  $query = db_insert('block_role')
    ->fields(array(
    'rid',
    'module',
    'delta',
  ));
  foreach (array_filter($form_state['values']['roles']) as $rid) {
    $query
      ->values(array(
      'rid' => $rid,
      'module' => $form_state['values']['module'],
      'delta' => $delta,
    ));
  }
  $query
    ->execute();

  // Store regions per theme for this block.
  foreach ($form_state['values']['regions'] as $theme => $region) {
    db_merge('block')
      ->key(array(
      'theme' => $theme,
      'delta' => $delta,
      'module' => $form_state['values']['module'],
    ))
      ->fields(array(
      'region' => $region == BLOCK_REGION_NONE ? '' : $region,
      'pages' => trim($form_state['values']['pages']),
      'status' => (int) ($region != BLOCK_REGION_NONE),
    ))
      ->execute();
  }
  drupal_set_message(t('The block has been created.'));
  cache_clear_all();
  $form_state['redirect'] = 'admin/structure/block';
}