Projet

Général

Profil

Révision a2baadd1

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform_validation/webform_validation.admin.inc
10 10
 */
11 11
function webform_validation_manage($node) {
12 12
  $rules = webform_validation_get_webform_rules($node);
13
  $output = '';
14
  $output .= theme('webform_validation_manage_overview', array('rules' => $rules, 'node' => $node));
15
  $output .= theme('webform_validation_manage_add_rule', array('nid' => $node->nid));
13
  $output = array();
14
  $output['webform_validation_manage_overview_form'] = drupal_get_form('webform_validation_manage_overview_form', $rules, $node);
15
  $output['webform_validation_manage_add_rule'] = array(
16
    '#theme' => 'webform_validation_manage_add_rule',
17
    '#nid' => $node->nid,
18
  );
16 19
  return $output;
17 20
}
18 21

  
......
27 30
  return $rules;
28 31
}
29 32

  
33

  
30 34
/**
31
 * Themable function to list the rules assigned to a webform
35
 * Themable function to list and re-order the rules assigned to a webform
32 36
 */
33
function theme_webform_validation_manage_overview($variables) {
34
  $rules = $variables['rules'];
35
  $node = $variables['node'];
37
function theme_webform_validation_manage_overview_form($variables) {
38
  $form = $variables['form'];
39
  $header = array(t('Rule name'), t('Validator'), t('Components'), t('Weight'), array(
40
    'data' => t('Operations'),
41
    'colspan' => 2,
42
  ));
36 43

  
37
  $header = array(t('Rule name'), t('Validator'), t('Components'), array(
38
      'data' => t('Operations'),
39
      'colspan' => 2,
40
    ));
41
  $validators = webform_validation_get_validators_selection();
42
  if (!empty($rules)) {
43
    foreach ($rules as $rule) {
44
      $component_info = webform_validation_rule_components_basic($rule['components']);
45
      $row = array();
44
  $rows = array();
45
  foreach (element_children($form) as $rule) {
46
    $row = array();
47
    foreach (element_children($form[$rule]) as $item) {
48
      //unset the titles of the form elements, since we are displaying them in a table with a header.
49
      unset($form[$rule][$item]['#title']);
50
      //add a class to the weight field
51
      $form[$rule]['weight']['#attributes']['class'] = array('ruleid-weight');
46 52
      $row[] = array(
47
        'data' => check_plain($rule['rulename']),
53
        'data' => drupal_render($form[$rule][$item]),
48 54
      );
49
      $row[] = array(
50
        'data' => $validators[$rule['validator']],
51
      );
52
      $row[] = array(
53
        'data' => theme('item_list', array('items' => $component_info)),
54
      );
55
      $row[] = array(
56
        'data' => l(t('Edit'), 'node/' . $node->nid . '/webform/validation/edit/' . $rule['validator'] . '/' . $rule['ruleid'], array("query" => drupal_get_destination())),
57
      );
58
      $row[] = array(
59
        'data' => l(t('Delete'), 'node/' . $node->nid . '/webform/validation/delete/' . $rule['ruleid'], array("query" => drupal_get_destination())),
55
    }
56
    if (count($row) > 1) {
57
      $rows[] = array(
58
        'data' => $row,
59
        'class' => array('draggable'),
60 60
      );
61
      $rows[] = $row;
61
    }
62
    // Hide any fieldsets, since we are displaying the form in a table.
63
    if (isset($form[$rule]['#type']) && $form[$rule]['#type'] === 'fieldset') {
64
      hide($form[$rule]);
62 65
    }
63 66
  }
64
  else {
67
  $drag = TRUE;
68
  if (!$rows) {
69
    $drag = FALSE;
65 70
    $rows[][] = array(
66 71
      'data' => t('No validation rules available.'),
67 72
      'colspan' => 5,
68 73
    );
69 74
  }
75
  $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'webform-validation-overview-form')));
76
  $output .= drupal_render_children($form);
77
  if ($drag) {
78
    drupal_add_tabledrag('webform-validation-overview-form', 'order', 'sibling', 'ruleid-weight');
79
  }
80
  return $output;
81
}
82

  
83
/**
84
 * Form to list and reorder the rules assigned to a webform
85
 */
86
function webform_validation_manage_overview_form($form, &$form_state, $rules, $node) {
87
  $form = array();
88
  $form['#tree'] = TRUE;
89
  $validators = webform_validation_get_validators_selection();
70 90

  
71
  return theme('table', array('header' => $header, 'rows' => $rows));
91
  foreach ($rules as $rule) {
92
    $component_info = webform_validation_rule_components_basic($rule['components']);
93
    $form[$rule['ruleid']] = array(
94
      '#type' => 'fieldset',
95
    );
96
    $form[$rule['ruleid']]['name'] = array(
97
      '#type' => 'item',
98
      '#title' => t('Name'),
99
      '#markup' => check_plain($rule['rulename']),
100
    );
101
    $form[$rule['ruleid']]['validator'] = array(
102
      '#type' => 'item',
103
      '#title' => t('Validator'),
104
      '#markup' => $validators[$rule['validator']],
105
    );
106
    $form[$rule['ruleid']]['components'] = array(
107
      '#type' => 'item',
108
      '#title' => t('Components'),
109
      '#markup' => theme('item_list', array('items' => $component_info)),
110
    );
111
    $form[$rule['ruleid']]['weight'] = array(
112
      '#type' => 'weight',
113
      '#title' => t('Weight'),
114
      '#default_value' => $rule['weight'],
115
      '#description' => t('Optional. By changing the order of validation rules, you can use code that relies on earlier validation functions being completed.'),
116
    );
117
    $form[$rule['ruleid']]['actions'] = array('#type' => 'actions');
118
    $form[$rule['ruleid']]['actions']['edit'] = array(
119
      '#type' => 'item',
120
      '#markup' => l(t('Edit'), 'node/' . $node->nid . '/webform/validation/edit/' . $rule['validator'] . '/' . $rule['ruleid'], array("query" => drupal_get_destination())),
121
    );
122
    $form[$rule['ruleid']]['actions']['delete'] = array(
123
      '#type' => 'item',
124
      '#markup' => l(t('Delete'), 'node/' . $node->nid . '/webform/validation/delete/' . $rule['ruleid'], array("query" => drupal_get_destination())),
125
    );
126
  }
127
  if (count($rules) > 1) {
128
    $form['submit'] = array(
129
      '#type' => 'submit',
130
      '#value' => t('Save rule order'),
131
    );
132
  }
133

  
134
  return $form;
135
}
136

  
137
/**
138
 * Submit function for rule overview form.
139
 */
140
function webform_validation_manage_overview_form_submit($form, $form_state) {
141
  //Save the rule weights.
142
  foreach ($form_state['values'] as $ruleid => $value) {
143
    if (is_numeric($ruleid)) {
144
      $update = db_update('webform_validation_rule')
145
        ->fields(array(
146
          'weight' => $value['weight'],
147
        ))
148
        ->condition('ruleid', $ruleid)
149
        ->execute();
150
    }
151
  }
152
  drupal_set_message(t('The order of the validation rules has been saved.'));
72 153
}
73 154

  
74 155
/**
......
256 337
 */
257 338
function webform_validation_delete_rule_submit($form, &$form_state) {
258 339
  $ruleid = $form_state['values']['ruleid'];
259
  webform_dynamic_delete_rule($ruleid);
260 340
  module_invoke_all('webform_validation', 'rule', 'delete', $ruleid);
341
  webform_dynamic_delete_rule($ruleid);
261 342
}

Formats disponibles : Unified diff