Projet

Général

Profil

Révision d0ed0aa6

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform_validation/README.md
10 10

  
11 11
- Numeric values (optionally specify min and / or max value)
12 12
- Minimum length
13
- Maximum length
13
- Maximum length (automatically integrates a JavaScript counter if the optional
14
  Maxlength module is installed)
14 15
- Minimum number of words
15 16
- Maximum number of words
16 17
- Equal values on multiple fields
drupal7/sites/all/modules/webform_validation/modules/webform_validation_testing/webform_validation_testing.info
5 5
dependencies[] = webform_validation
6 6
hidden = TRUE
7 7

  
8
; Information added by Drupal.org packaging script on 2020-01-17
9
version = "7.x-1.17"
8
; Information added by Drupal.org packaging script on 2020-08-04
9
version = "7.x-1.18"
10 10
core = "7.x"
11 11
project = "webform_validation"
12
datestamp = "1579281188"
12
datestamp = "1596547891"
drupal7/sites/all/modules/webform_validation/webform_validation.admin.inc
12 12
 * rule.
13 13
 */
14 14
function webform_validation_manage($node) {
15
  $rules = webform_validation_get_webform_rules($node);
15
  $rules = webform_validation_get_node_rules($node->nid);
16 16
  $output = array();
17 17
  $output['webform_validation_manage_overview_form'] = drupal_get_form('webform_validation_manage_overview_form', $rules, $node);
18 18
  $output['webform_validation_manage_add_rule'] = array(
......
24 24

  
25 25
/**
26 26
 * Get the list of rules associated with the webform.
27
 *
28
 * @deprecated in webform_validation:7.x-1.18 and is removed from webform_validation:7.x-2.0. Use webform_validation_get_node_rules().
29
 * @see https://www.drupal.org/project/webform_validation/issues/3104316
27 30
 */
28 31
function webform_validation_get_webform_rules($node) {
29 32
  if (in_array($node->type, webform_variable_get('webform_node_types'))) {
30
    $webform_nid = $node->nid;
31
    $rules = webform_validation_get_node_rules($node->nid);
33
    return webform_validation_get_node_rules($node->nid);
32 34
  }
33
  return $rules;
34 35
}
35 36

  
36 37
/**
......
249 250
      '#required' => (bool) $required,
250 251
      '#size' => 60,
251 252
      '#maxlength' => NULL,
252
      '#default_value' => $rule['data'],
253
      '#default_value' => isset($rule['data']) ? $rule['data'] : NULL,
253 254
      '#weight' => 4,
254 255
    );
255 256
  }
......
259 260
      '#type' => 'checkbox',
260 261
      '#title' => t('Negate rule'),
261 262
      '#description' => t('Validate the inverse of the rule.'),
262
      '#default_value' => $rule['negate'],
263
      '#default_value' => isset($rule['negate']) ? $rule['negate'] : NULL,
263 264
      '#weight' => 5,
264 265
    );
265 266
  }
......
272 273
      '#required' => TRUE,
273 274
      '#size' => 60,
274 275
      '#maxlength' => 2048,
275
      '#default_value' => $rule['error_message'],
276
      '#default_value' => isset($rule['error_message']) ? $rule['error_message'] : NULL,
276 277
      '#weight' => 5,
277 278
    );
278 279
  }
......
306 307
  $rule_validator = webform_validation_get_validator_info($values['validator']);
307 308

  
308 309
  // Validate custom data.
309
  if ($values['data'] && !empty($rule_validator['custom_data']['validate_regex']) && !preg_match($rule_validator['custom_data']['validate_regex'], $values['data'])) {
310
  if (!empty($values['data']) && !empty($rule_validator['custom_data']['validate_regex']) && !preg_match($rule_validator['custom_data']['validate_regex'], $values['data'])) {
310 311
    form_set_error('data', $rule_validator['custom_data']['label'] . ' ' . t('is invalid.'));
311 312
  }
312 313

  
......
367 368
    );
368 369
  }
369 370

  
370
  return confirm_form($form, t('Are you sure you want to delete the rule %name?', array('%name' => $rule['rulename'])), isset($_GET['destination']) ? $_GET['destination'] : $_GET['q'], t('This action cannot be undone.'), t('Delete'), t('Cancel')
371
  );
371
  return confirm_form(
372
    $form,
373
    t('Are you sure you want to delete the rule %name?', array('%name' => $rule['rulename'])),
374
    'node/' . $rule['nid'] . '/webform/validation',
375
    NULL,
376
    t('Delete'));
372 377
}
373 378

  
374 379
/**
drupal7/sites/all/modules/webform_validation/webform_validation.info
8 8
files[] = tests/WebformValidationUnitTestCase.test
9 9
php = 5.3
10 10

  
11
; Information added by Drupal.org packaging script on 2020-01-17
12
version = "7.x-1.17"
11
; Information added by Drupal.org packaging script on 2020-08-04
12
version = "7.x-1.18"
13 13
core = "7.x"
14 14
project = "webform_validation"
15
datestamp = "1579281188"
15
datestamp = "1596547891"
drupal7/sites/all/modules/webform_validation/webform_validation.module
59 59
}
60 60

  
61 61
/**
62
 * Loads validation rule from menu parameter.
62
 * Load a validation rule.
63
 *
64
 * @param int $ruleid
65
 *   The rule ID.
66
 *
67
 * @return array|false
68
 *   The rule or FALSE if no rule exists.
63 69
 */
64 70
function webform_validation_rule_load($ruleid) {
65
  return webform_validation_get_rule($ruleid);
71
  $result = db_query("SELECT ruleid, rulename, nid, validator, data, error_message, negate, weight FROM {webform_validation_rule} WHERE ruleid = :ruleid", array(':ruleid' => $ruleid), array('fetch' => PDO::FETCH_ASSOC));
72
  $rule = $result->fetchAssoc();
73
  if (!$rule) {
74
    return FALSE;
75
  }
76
  $rule['components'] = webform_validation_get_rule_components($ruleid, $rule['nid']);
77
  $rule['negate'] = (bool) $rule['negate'];
78
  return $rule;
66 79
}
67 80

  
68 81
/**
......
86 99
 */
87 100
function webform_validation_form_webform_client_form_alter(&$form, &$form_state, $form_id) {
88 101
  $form['#validate'][] = 'webform_validation_validate';
102
  if (module_exists('maxlength')) {
103
    $nid = substr($form_id, strlen('webform_client_form') + 1);
104
    $rules = webform_validation_get_node_rules($nid);
105
    foreach ($rules as $ruleid => $rule) {
106
      if ($rule['validator'] == 'max_length') {
107
        $length_limit = $rule['data'];
108
        $components = $rule['components'];
109
        foreach ($components as $cid => $component) {
110
          // Define $form_element as the webform element representing this
111
          // component, even if it's nested in multiple arrays, as webform
112
          // elemens often are (e.g., fieldsets). Assign by reference here,
113
          // since we need to modify the form element itself and don't know
114
          // its array depth or keys by which to access it.
115
          $form_element = &_webform_validation_get_webform_element($component, $form);
116
          // Append to this form element the relevant properties which are
117
          // supported by maxlength module.
118
          $form_element['#pre_render'][] = 'maxlength_pre_render';
119
          $form_element['#maxlength'] = $length_limit;
120
          $form_element['#maxlength_js'] = TRUE;
121
        }
122
      }
123
    }
124
  }
89 125
}
90 126

  
91 127
/**
......
399 435
function webform_validation_node_delete($node) {
400 436
  $rules = webform_validation_get_node_rules($node->nid);
401 437
  if ($rules) {
438
    $transaction = db_transaction();
402 439
    foreach (array_keys($rules) as $ruleid) {
403 440
      webform_dynamic_delete_rule($ruleid);
404 441
    }
......
458 495
    return FALSE;
459 496
  }
460 497

  
498
  $transaction = db_transaction();
499

  
461 500
  drupal_write_record('webform_validation_rule', $values, $primary_keys);
462 501

  
463 502
  // Delete existing component records for this ruleid.
......
577 616
}
578 617

  
579 618
/**
580
 * Implements hook_uuid_entity_uuid_save().
619
 * Implements hook_entity_uuid_save().
581 620
 */
582 621
function webform_validation_entity_uuid_save($node, $entity_type) {
583 622
  if ($entity_type == 'node') {
584 623
    if (isset($node->webform['validation'])) {
585 624
      $rules = $node->webform['validation'];
586 625
      $orig_rules = webform_validation_get_node_rules_assoc($node->nid);
626
      $transaction = db_transaction();
587 627
      // Delete obsolete rules.
588 628
      $delete = array_diff_key($orig_rules, $rules);
589 629
      foreach ($delete as $rule) {
......
611 651
      }
612 652
    }
613 653
  }
654
}
614 655

  
656
/**
657
 * Get a reference to a specific webform element.
658
 *
659
 * (For a given webform_validation rule component, and a given Drupal webform
660
 * form, get a reference to the webform element represented by the rule
661
 * component; return the correct element regardless of how deeply it's nested
662
 * in webform fieldsets or other wrappers.)
663
 *
664
 * @param array $component
665
 *   Webform validation rule component.
666
 * @param array $form
667
 *   Drupal webform form.
668
 *
669
 * @return array
670
 *   Reference to the webform element represented by the rule component.
671
 */
672
function &_webform_validation_get_webform_element(array $component, array &$form) {
673
  // Define an array of ancestors, beginning with the component itself.
674
  $component_ancestors = array($component['form_key']);
675
  // Define the parent-id, starting with the parent-id of the component itself,
676
  // if any.
677
  $pid = $component['pid'];
678
  // Look into $form['#node']->webform['components'][$pid] to get any parent
679
  // of the component, and continue working up the family tree until there is
680
  // no more parent-id.
681
  while ($pid) {
682
    $parent = $form['#node']->webform['components'][$pid];
683
    // Prepend the parent form_key to the array of ancestors. This causes the
684
    // array of ancestors to be ordered from ancestor to descendant.
685
    array_unshift($component_ancestors, $parent['form_key']);
686
    // Note this parent's parent-id, if any.
687
    $pid = $parent['pid'];
688
  }
689
  // $component_ancestors now contains the ordered ancestry. Cycle through it to
690
  // get the correct member of $form['submitted']. Assign by reference so that
691
  // we have a good reference to $webform_element to return.
692
  $webform_element = &$form['submitted'];
693
  foreach ($component_ancestors as $ancestor) {
694
    $webform_element = &$webform_element[$ancestor];
695
  }
696
  return $webform_element;
615 697
}
drupal7/sites/all/modules/webform_validation/webform_validation.rules.inc
7 7

  
8 8
/**
9 9
 * Get a rule entry.
10
 *
11
 * @deprecated in webform_validation:7.x-1.18 and is removed from webform_validation:7.x-2.0. Use webform_validation_rule_load().
12
 * @see https://www.drupal.org/project/webform_validation/issues/3104320
10 13
 */
11 14
function webform_validation_get_rule($ruleid) {
12
  $result = db_query("SELECT ruleid, rulename, nid, validator, data, error_message, negate, weight FROM {webform_validation_rule} WHERE ruleid = :ruleid", array(':ruleid' => $ruleid), array('fetch' => PDO::FETCH_ASSOC));
13
  $rule = $result->fetchAssoc();
14
  $rule['components'] = webform_validation_get_rule_components($ruleid, $rule['nid']);
15
  $rule['negate'] = (bool) $rule['negate'];
16
  return $rule;
15
  return webform_validation_rule_load($ruleid);
17 16
}
18 17

  
19 18
/**
......
124 123
 *   The ruleid of the rule to delete.
125 124
 */
126 125
function webform_dynamic_delete_rule($ruleid) {
126
  $transaction = db_transaction();
127 127
  // Delete rule.
128 128
  db_delete('webform_validation_rule')
129 129
    ->condition('ruleid', $ruleid)
drupal7/sites/all/modules/webform_validation/webform_validation.validators.inc
458 458
    );
459 459
  }
460 460

  
461
  if (module_exists('maxlength')) {
462
    $validators['max_length']['description'] .= ' ' . t('A JavaScript counter will show the number of characters remaining as the user types.');
463
  }
464

  
461 465
  return $validators;
462 466
}
463 467

  

Formats disponibles : Unified diff