You are here

function accordion_block_config_settings_submit in Accordion Blocks 7.3

Same name and namespace in other branches
  1. 7.2 accordion_blocks.module \accordion_block_config_settings_submit()

From submit handler for accordion_block_config_settings().

File

./accordion_blocks.module, line 293

Code

function accordion_block_config_settings_submit($form, $form_state) {
  $values = $form_state['values'];
  $block_values = array();
  $count = 0;
  foreach ($values as $key => $form_value) {
    if ($key == 'block_' . $count) {
      $block_values['block_' . $count] = $form_value;
      $count++;
    }
  }
  $content = serialize($block_values);
  $title = $values['accordion_block_title'];
  $id = '';
  if (array_key_exists('id', $values)) {
    $id = $values['id'];
  }
  if (!$id) {
    $insert = db_insert('accordion_blocks')
      ->fields(array(
      'title',
      'content',
    ))
      ->values(array(
      'title' => $title,
      'content' => $content,
    ))
      ->execute();
    if ($insert) {
      drupal_set_message(t("Added accordion block sucessfully"));
      drupal_goto('admin/structure/accordion_block');
    }
  }
  else {
    $update = db_update('accordion_blocks')
      ->fields(array(
      'title' => $title,
      'content' => $content,
    ))
      ->condition('id', $id, '=')
      ->execute();
    if ($update) {
      drupal_set_message(t("Updated accordion block sucessfully"));
      drupal_goto('admin/structure/accordion_block');
    }
  }
}