You are here

function faq_order_settings_reorder_form_submit in Frequently Asked Questions 7.2

Same name and namespace in other branches
  1. 6 faq.admin.inc \faq_order_settings_reorder_form_submit()
  2. 7 faq.admin.inc \faq_order_settings_reorder_form_submit()

Save the options set by the user in the FAQ Settings - Weight tab.

Parameters

$form: Array, containing the form structure.

&$form_state: $form_state['values'] stores the submitted values from the form.

1 string reference to 'faq_order_settings_reorder_form_submit'
faq_order_settings_form in ./faq.admin.inc
Define the elements for the FAQ Settings page - order tab.

File

./faq.admin.inc, line 621
Administrative page callbacks for the faq module.

Code

function faq_order_settings_reorder_form_submit($form, &$form_state) {
  if ($form_state['values']['op'] == t('Save order') && !empty($form_state['values']['order_no_cats'])) {
    foreach ($form_state['values']['order_no_cats'] as $i => $faq) {
      $nid = $faq['nid'];
      $index = $faq['sort'];
      db_merge('faq_weights')
        ->fields(array(
        'weight' => $index,
      ))
        ->key(array(
        'tid' => $form_state['values']['faq_category'],
        'nid' => $nid,
      ))
        ->execute();
      $result = NULL;

      // If node translation module enabled, update order of the translation
      // node counterparts.
      if (module_exists('translation')) {
        $node = node_load($nid);
        if ($node->tnid) {
          $translations = translation_node_get_translations($node->tnid);
          if (!empty($translations)) {
            foreach ($translations as $language => $tnode) {
              db_merge('faq_weights')
                ->fields(array(
                'weight' => $index,
              ))
                ->key(array(
                'tid' => $form_state['values']['faq_category'],
                'nid' => $tnode->nid,
              ))
                ->execute();
            }
          }
        }
      }
    }
    drupal_set_message(t('Configuration has been updated.'));
  }
}