You are here

function _smart_paging_settings_submit in Smart Paging 7.2

Same name and namespace in other branches
  1. 7 smart_paging.module \_smart_paging_settings_submit()

Smart Paging settings submit handler.

1 string reference to '_smart_paging_settings_submit'
smart_paging_form_alter in ./smart_paging.module
Implements hook_form_alter()

File

./smart_paging.module, line 370
Provides smart paging capability to Drupal contents.

Code

function _smart_paging_settings_submit($form, &$form_state) {
  if (isset($form_state['values']['smart_paging_use_default']) && !$form_state['values']['smart_paging_use_default'] && isset($form_state['storage']['smart_paging_entity_id'])) {
    $smart_paging_use_default = $form_state['values']['smart_paging_use_default'];
    $entity_type = $form_state['storage']['smart_paging_entity_type'];
    $entity_id = $form_state['storage']['smart_paging_entity_id'];
    $config = array(
      'use_default' => $form_state['values']['smart_paging_use_default'],
      'method' => $form_state['values']['smart_paging_method'],
      'pagebreak' => $form_state['values']['smart_paging_pagebreak'],
      'character_count' => $form_state['values']['smart_paging_character_count'],
      'word_count' => $form_state['values']['smart_paging_word_count'],
      'title_suffix' => $form_state['values']['smart_paging_title_suffix'],
      'title_display_suffix' => $form_state['values']['smart_paging_title_display_suffix'],
    );
    try {
      db_insert('smart_paging')
        ->fields(array(
        'entity_id',
        'entity_type',
        'configuration',
      ))
        ->values(array(
        'entity_id' => $entity_id,
        'entity_type' => $entity_type,
        'configuration' => serialize($config),
      ))
        ->execute();
    } catch (Exception $error) {
      db_update('smart_paging')
        ->fields(array(
        'configuration' => serialize($config),
      ))
        ->condition('entity_id', $entity_id)
        ->condition('entity_type', $entity_type)
        ->execute();
    }
  }
  elseif (isset($form_state['values']['smart_paging_use_default']) && $form_state['values']['smart_paging_use_default']) {
    if (isset($form_state['storage']['smart_paging_entity_id']) && isset($form_state['storage']['smart_paging_entity_type'])) {
      db_delete('smart_paging')
        ->condition('entity_id', $form_state['storage']['smart_paging_entity_id'])
        ->condition('entity_type', $form_state['storage']['smart_paging_entity_type'])
        ->execute();
    }
  }
}