Commit 69f93262 authored by theo lem's avatar theo lem
Browse files

updating webform_confirm_email and webform_validation

parent 2c0311ed
......@@ -8,8 +8,8 @@ dependencies[] = webform (>=7.x-4.16)
stylesheets[all][] = webform_confirm_email.css
; Information added by Drupal.org packaging script on 2019-10-29
version = "7.x-2.14"
; Information added by Drupal.org packaging script on 2020-09-08
version = "7.x-2.15"
core = "7.x"
project = "webform_confirm_email"
datestamp = "1572344887"
datestamp = "1599581158"
......@@ -29,8 +29,8 @@ function webform_confirm_email_schema() {
),
'email' => array(
'description' => 'The confirmation email that will be send once the confirmation URL is used',
'type' => 'blob',
'size' => 'big',
'type' => 'text',
'size' => 'medium',
'serialize' => TRUE,
),
'created' => array(
......
......@@ -91,10 +91,8 @@ function webform_confirm_email_mail_alter(&$message) {
'sid' => $sid,
'email' => $message,
'created' => $_SERVER['REQUEST_TIME'],
);
);
$message['send'] = FALSE; // prevents drupal_mail from actually sending the message
unset($obj["email_message"]["params"]["node"]);
drupal_write_record('webform_confirm_email_queued_emails', $obj);
}
}
......@@ -133,8 +131,7 @@ function webform_confirm_email_confirmation($node, $submission, $eid) {
->fetchCol();
foreach ($messages as $email_message) {
$email_message = unserialize($email_message);
$email_message = unserialize($email_message);
// Concatenate and wrap the e-mail body.
if (is_array($email_message['body'])) {
$email_message['body'] = implode("\n\n", $email_message['body']);
......@@ -283,39 +280,21 @@ function webform_confirm_email_menu() {
* Implements hook_menu_alter().
*/
function webform_confirm_email_menu_alter(&$items) {
if (isset($items['node/%webform_menu/webform-results']) == TRUE) {
$items['node/%webform_menu/webform-results'] = array(
'title' => 'Results',
'page callback' => 'webform_confirm_email_results_submissions',
'page arguments' => array(1, FALSE, '50'),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => drupal_get_path('module', 'webform_confirm_email') . '/webform_confirm_email.report.inc',
'weight' => 2,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
$items['node/%webform_menu/webform-results/submissions'] = array(
'title' => 'Submissions',
'page callback' => 'webform_confirm_email_results_submissions',
'page arguments' => array(1, FALSE, '50'),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => drupal_get_path('module', 'webform_confirm_email') . '/webform_confirm_email.report.inc',
'weight' => 4,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['node/%webform_menu/webform-results/table'] = array(
'title' => 'Table',
'page callback' => 'webform_confirm_email_results_table',
'page arguments' => array(1, '50'),
'access callback' => 'webform_results_access',
'access arguments' => array(1),
'file' => drupal_get_path('module', 'webform_confirm_email') . '/webform_confirm_email.report.inc',
'weight' => 6,
'type' => MENU_LOCAL_TASK,
);
}
$items['node/%webform_menu/webform-results'] = array(
'page callback' => 'webform_confirm_email_results_submissions',
'file path' => drupal_get_path('module', 'webform_confirm_email'),
'file' => 'webform_confirm_email.report.inc',
) + $items['node/%webform_menu/webform-results'];
$items['node/%webform_menu/webform-results/submissions'] = array(
'page callback' => 'webform_confirm_email_results_submissions',
'file path' => drupal_get_path('module', 'webform_confirm_email'),
'file' => 'webform_confirm_email.report.inc',
) + $items['node/%webform_menu/webform-results/submissions'];
$items['node/%webform_menu/webform-results/table'] = array(
'page callback' => 'webform_confirm_email_results_table',
'file path' => drupal_get_path('module', 'webform_confirm_email'),
'file' => 'webform_confirm_email.report.inc',
) + $items['node/%webform_menu/webform-results/table'];
}
/**
......
......@@ -10,7 +10,8 @@ The following validation rules are currently included:
- Numeric values (optionally specify min and / or max value)
- Minimum length
- Maximum length
- Maximum length (automatically integrates a JavaScript counter if the optional
Maxlength module is installed)
- Minimum number of words
- Maximum number of words
- Equal values on multiple fields
......
......@@ -5,8 +5,8 @@ package = Testing
dependencies[] = webform_validation
hidden = TRUE
; Information added by Drupal.org packaging script on 2020-01-17
version = "7.x-1.17"
; Information added by Drupal.org packaging script on 2020-08-04
version = "7.x-1.18"
core = "7.x"
project = "webform_validation"
datestamp = "1579281188"
datestamp = "1596547891"
......@@ -12,7 +12,7 @@
* rule.
*/
function webform_validation_manage($node) {
$rules = webform_validation_get_webform_rules($node);
$rules = webform_validation_get_node_rules($node->nid);
$output = array();
$output['webform_validation_manage_overview_form'] = drupal_get_form('webform_validation_manage_overview_form', $rules, $node);
$output['webform_validation_manage_add_rule'] = array(
......@@ -24,13 +24,14 @@ function webform_validation_manage($node) {
/**
* Get the list of rules associated with the webform.
*
* @deprecated in webform_validation:7.x-1.18 and is removed from webform_validation:7.x-2.0. Use webform_validation_get_node_rules().
* @see https://www.drupal.org/project/webform_validation/issues/3104316
*/
function webform_validation_get_webform_rules($node) {
if (in_array($node->type, webform_variable_get('webform_node_types'))) {
$webform_nid = $node->nid;
$rules = webform_validation_get_node_rules($node->nid);
return webform_validation_get_node_rules($node->nid);
}
return $rules;
}
/**
......@@ -249,7 +250,7 @@ function webform_validation_manage_rule($form, $form_state, $node, $action, $val
'#required' => (bool) $required,
'#size' => 60,
'#maxlength' => NULL,
'#default_value' => $rule['data'],
'#default_value' => isset($rule['data']) ? $rule['data'] : NULL,
'#weight' => 4,
);
}
......@@ -259,7 +260,7 @@ function webform_validation_manage_rule($form, $form_state, $node, $action, $val
'#type' => 'checkbox',
'#title' => t('Negate rule'),
'#description' => t('Validate the inverse of the rule.'),
'#default_value' => $rule['negate'],
'#default_value' => isset($rule['negate']) ? $rule['negate'] : NULL,
'#weight' => 5,
);
}
......@@ -272,7 +273,7 @@ function webform_validation_manage_rule($form, $form_state, $node, $action, $val
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 2048,
'#default_value' => $rule['error_message'],
'#default_value' => isset($rule['error_message']) ? $rule['error_message'] : NULL,
'#weight' => 5,
);
}
......@@ -306,7 +307,7 @@ function webform_validation_manage_rule_validate($form, &$form_state) {
$rule_validator = webform_validation_get_validator_info($values['validator']);
// Validate custom data.
if ($values['data'] && !empty($rule_validator['custom_data']['validate_regex']) && !preg_match($rule_validator['custom_data']['validate_regex'], $values['data'])) {
if (!empty($values['data']) && !empty($rule_validator['custom_data']['validate_regex']) && !preg_match($rule_validator['custom_data']['validate_regex'], $values['data'])) {
form_set_error('data', $rule_validator['custom_data']['label'] . ' ' . t('is invalid.'));
}
......@@ -367,8 +368,12 @@ function webform_validation_delete_rule($form, &$form_state, $rule) {
);
}
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')
);
return confirm_form(
$form,
t('Are you sure you want to delete the rule %name?', array('%name' => $rule['rulename'])),
'node/' . $rule['nid'] . '/webform/validation',
NULL,
t('Delete'));
}
/**
......
......@@ -8,8 +8,8 @@ files[] = tests/WebformValidationTestCase.test
files[] = tests/WebformValidationUnitTestCase.test
php = 5.3
; Information added by Drupal.org packaging script on 2020-01-17
version = "7.x-1.17"
; Information added by Drupal.org packaging script on 2020-08-04
version = "7.x-1.18"
core = "7.x"
project = "webform_validation"
datestamp = "1579281188"
datestamp = "1596547891"
......@@ -59,10 +59,23 @@ function webform_validation_menu() {
}
/**
* Loads validation rule from menu parameter.
* Load a validation rule.
*
* @param int $ruleid
* The rule ID.
*
* @return array|false
* The rule or FALSE if no rule exists.
*/
function webform_validation_rule_load($ruleid) {
return webform_validation_get_rule($ruleid);
$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));
$rule = $result->fetchAssoc();
if (!$rule) {
return FALSE;
}
$rule['components'] = webform_validation_get_rule_components($ruleid, $rule['nid']);
$rule['negate'] = (bool) $rule['negate'];
return $rule;
}
/**
......@@ -86,6 +99,29 @@ function webform_validation_theme() {
*/
function webform_validation_form_webform_client_form_alter(&$form, &$form_state, $form_id) {
$form['#validate'][] = 'webform_validation_validate';
if (module_exists('maxlength')) {
$nid = substr($form_id, strlen('webform_client_form') + 1);
$rules = webform_validation_get_node_rules($nid);
foreach ($rules as $ruleid => $rule) {
if ($rule['validator'] == 'max_length') {
$length_limit = $rule['data'];
$components = $rule['components'];
foreach ($components as $cid => $component) {
// Define $form_element as the webform element representing this
// component, even if it's nested in multiple arrays, as webform
// elemens often are (e.g., fieldsets). Assign by reference here,
// since we need to modify the form element itself and don't know
// its array depth or keys by which to access it.
$form_element = &_webform_validation_get_webform_element($component, $form);
// Append to this form element the relevant properties which are
// supported by maxlength module.
$form_element['#pre_render'][] = 'maxlength_pre_render';
$form_element['#maxlength'] = $length_limit;
$form_element['#maxlength_js'] = TRUE;
}
}
}
}
}
/**
......@@ -399,6 +435,7 @@ function webform_validation_node_insert($node) {
function webform_validation_node_delete($node) {
$rules = webform_validation_get_node_rules($node->nid);
if ($rules) {
$transaction = db_transaction();
foreach (array_keys($rules) as $ruleid) {
webform_dynamic_delete_rule($ruleid);
}
......@@ -458,6 +495,8 @@ function webform_validation_rule_save(array $values) {
return FALSE;
}
$transaction = db_transaction();
drupal_write_record('webform_validation_rule', $values, $primary_keys);
// Delete existing component records for this ruleid.
......@@ -577,13 +616,14 @@ function webform_validation_uuid_node_features_export_render_alter(&$export, $no
}
/**
* Implements hook_uuid_entity_uuid_save().
* Implements hook_entity_uuid_save().
*/
function webform_validation_entity_uuid_save($node, $entity_type) {
if ($entity_type == 'node') {
if (isset($node->webform['validation'])) {
$rules = $node->webform['validation'];
$orig_rules = webform_validation_get_node_rules_assoc($node->nid);
$transaction = db_transaction();
// Delete obsolete rules.
$delete = array_diff_key($orig_rules, $rules);
foreach ($delete as $rule) {
......@@ -611,5 +651,47 @@ function webform_validation_entity_uuid_save($node, $entity_type) {
}
}
}
}
/**
* Get a reference to a specific webform element.
*
* (For a given webform_validation rule component, and a given Drupal webform
* form, get a reference to the webform element represented by the rule
* component; return the correct element regardless of how deeply it's nested
* in webform fieldsets or other wrappers.)
*
* @param array $component
* Webform validation rule component.
* @param array $form
* Drupal webform form.
*
* @return array
* Reference to the webform element represented by the rule component.
*/
function &_webform_validation_get_webform_element(array $component, array &$form) {
// Define an array of ancestors, beginning with the component itself.
$component_ancestors = array($component['form_key']);
// Define the parent-id, starting with the parent-id of the component itself,
// if any.
$pid = $component['pid'];
// Look into $form['#node']->webform['components'][$pid] to get any parent
// of the component, and continue working up the family tree until there is
// no more parent-id.
while ($pid) {
$parent = $form['#node']->webform['components'][$pid];
// Prepend the parent form_key to the array of ancestors. This causes the
// array of ancestors to be ordered from ancestor to descendant.
array_unshift($component_ancestors, $parent['form_key']);
// Note this parent's parent-id, if any.
$pid = $parent['pid'];
}
// $component_ancestors now contains the ordered ancestry. Cycle through it to
// get the correct member of $form['submitted']. Assign by reference so that
// we have a good reference to $webform_element to return.
$webform_element = &$form['submitted'];
foreach ($component_ancestors as $ancestor) {
$webform_element = &$webform_element[$ancestor];
}
return $webform_element;
}
......@@ -7,13 +7,12 @@
/**
* Get a rule entry.
*
* @deprecated in webform_validation:7.x-1.18 and is removed from webform_validation:7.x-2.0. Use webform_validation_rule_load().
* @see https://www.drupal.org/project/webform_validation/issues/3104320
*/
function webform_validation_get_rule($ruleid) {
$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));
$rule = $result->fetchAssoc();
$rule['components'] = webform_validation_get_rule_components($ruleid, $rule['nid']);
$rule['negate'] = (bool) $rule['negate'];
return $rule;
return webform_validation_rule_load($ruleid);
}
/**
......@@ -124,6 +123,7 @@ function webform_validation_rule_components_basic($components) {
* The ruleid of the rule to delete.
*/
function webform_dynamic_delete_rule($ruleid) {
$transaction = db_transaction();
// Delete rule.
db_delete('webform_validation_rule')
->condition('ruleid', $ruleid)
......
......@@ -458,6 +458,10 @@ function webform_validation_webform_validation_validators() {
);
}
if (module_exists('maxlength')) {
$validators['max_length']['description'] .= ' ' . t('A JavaScript counter will show the number of characters remaining as the user types.');
}
return $validators;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment