Projet

Général

Profil

Révision c12e7e6a

Ajouté par Assos Assos il y a plus de 10 ans

Weekly update of contrib modules

Voir les différences:

htmltest/sites/all/modules/variable/variable.module
415 415
 * Form for variable list
416 416
 *
417 417
 * @param $list
418
 *   Variable name or list of variable names
418
 *   Variable name or list of variable names.
419
 * @param $options
420
 *   Optional array with variable options.
419 421
 */
420
function variable_edit_form($form, $form_state, $list, $options = array()) {
421
  // Pass on the values on the form for further reference.
422
  $form['#variable_edit_form'] = $list;
423
  form_load_include($form_state, 'form.inc', 'variable');
422
function variable_edit_form($form, &$form_state, $list, $options = array()) {
423
  $list = is_array($list) ? $list : array($list);
424
  $form = variable_base_form($form, $form_state, $list, $options);
424 425
  $form += variable_edit_subform($list, $options);
425 426
  return variable_settings_form($form, $options);
426 427
}
427 428

  
429
/**
430
 * Build base form for variable list without fields.
431
 *
432
 * @param $list
433
 *   List of variable names.
434
 * @param $options
435
 *   Optional array with variable options.
436
 */
437
function variable_base_form($form, &$form_state, $list, $options = array()) {
438
  form_load_include($form_state, 'form.inc', 'variable');
439
  // Pass on the values on the form for further reference.
440
  $form['#variable_edit_form'] = $list;
441
  $form['#variable_options'] = $options;
442
  // Run submit callback for variables in form.
443
  $form['#submit'][] = 'variable_form_submit_callback';
444
  return $form;
445
}
446

  
428 447
/**
429 448
 * Form elements for variable list.
430 449
 *
......
682 701
  }
683 702
}
684 703

  
704
/**
705
 * Implement validate callback.
706
 *
707
 * This needs to be in the module as it may be needed by form ajax callbacks.
708
 */
709
function variable_form_element_validate($element, &$form_state, $form) {
710
  $options = isset($form['#variable_options']) ? $form['#variable_options'] : array();
711
  $variable = $element['#variable'];
712
  variable_include($variable);
713
  $variable['value'] = isset($element['#value']) ? $element['#value'] : NULL;
714

  
715
  $error = $variable['validate callback']($variable, $options, $element, $form, $form_state);
685 716

  
717
  if ($error) {
718
    form_error($element, $error);
719
  }
720
}
686 721

  
687 722
/**
688 723
 * Implements hook_module_implements_alter().
......
765 800
  form_state_values_clean($form_state);
766 801
  // This may contain some realm options.
767 802
  $options = isset($form['#variable_options']) ? $form['#variable_options'] : array();
803

  
768 804
  // Now run regular settings submission but using variable_set_value()
769 805
  foreach ($form_state['values'] as $key => $value) {
770 806
    if (is_array($value) && isset($form_state['values']['array_filter'])) {

Formats disponibles : Unified diff