You are here

function language_hierarchy_form_submit in Language Hierarchy 7

Submit callback for the language_hierarchy_form form.

Updates the 'weight' column for each element in our table, taking into account that item's new order after the drag and drop actions have been performed.

File

./language_hierarchy_form.inc, line 305

Code

function language_hierarchy_form_submit($form, &$form_state) {

  // Reset static cache language list is not fetched from database
  drupal_static_reset('language_hierarchy_language_list');
  drupal_static_reset('language_hierarchy_get_children');
  drupal_static_reset('language_hierarchy_get_root_languages');

  // Because the form elements were keyed with the item ids from the database,
  // we can simply iterate through the submitted values.
  foreach ($form_state['values']['language_items'] as $langcode => $item) {

    // Update the language row in the db.
    db_update('languages')
      ->fields(array(
      'parent' => $item['pid'],
    ))
      ->condition('language', $item['id'], '=')
      ->execute();

    // Copy weights data to where locale submit function expects it.
    $form_state['values']['weight'][$item['id']] = $item['weight'];
  }

  // Run the original locale submit function to deal with core locale form functionality.
  // This includes enabling, settings default language and weight saving.
  module_load_include('inc', 'locale', 'locale.admin');
  locale_languages_overview_form_submit($form, $form_state);

  // Normalize weight, so languages are returned in correct order for flat lists.
  _language_hierarchy_normalize_weight();
}