diff --git a/components/date.inc b/components/date.inc index b79f31f..b9db4e4 100644 --- a/components/date.inc +++ b/components/date.inc @@ -134,6 +134,7 @@ function _webform_render_date($component, $value = NULL, $filter = TRUE) { '#theme_wrappers' => array('webform_element'), '#element_validate' => array('webform_validate_date'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); if ($component['extra']['datepicker']) { diff --git a/components/email.inc b/components/email.inc index f8fb148..38229e8 100644 --- a/components/email.inc +++ b/components/email.inc @@ -120,6 +120,7 @@ function _webform_render_email($component, $value = NULL, $filter = TRUE) { '#element_validate' => array('_webform_validate_email'), '#theme_wrappers' => array('webform_element'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); // Add an e-mail class for identifying the difference from normal textfields. diff --git a/components/fieldset.inc b/components/fieldset.inc index 92875b4..e4e9fdc 100644 --- a/components/fieldset.inc +++ b/components/fieldset.inc @@ -62,6 +62,7 @@ function _webform_render_fieldset($component, $value = NULL, $filter = TRUE) { '#attributes' => array('class' => array('webform-component-fieldset'), 'id' => 'webform-component-' . $component['form_key']), '#pre_render' => array('webform_fieldset_prerender'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); // Hide the fieldset title if #title_display is 'none'. diff --git a/components/file.inc b/components/file.inc index 6df31cb..f6dadb3 100644 --- a/components/file.inc +++ b/components/file.inc @@ -367,6 +367,7 @@ function _webform_render_file($component, $value = NULL, $filter = TRUE) { '#weight' => $component['weight'], '#theme_wrappers' => array('webform_element'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); return $element; diff --git a/components/grid.inc b/components/grid.inc index a53192b..733eff8 100644 --- a/components/grid.inc +++ b/components/grid.inc @@ -157,6 +157,7 @@ function _webform_render_grid($component, $value = NULL, $filter = TRUE) { '#theme_wrappers' => array('webform_element'), '#process' => array('webform_expand_grid'), '#webform_component' => $component, + '#translatable' => array('title', 'description', 'grid_options', 'grid_questions'), ); if ($value) { @@ -180,6 +181,7 @@ function webform_expand_grid($element) { if (!empty($element['#qrand'])) { _webform_shuffle_options($questions); } + $element['#options'] = $options; foreach ($questions as $key => $question) { if ($question != '') { @@ -193,6 +195,7 @@ function webform_expand_grid($element) { // Webform handles validation manually. '#validated' => TRUE, '#webform_validated' => FALSE, + '#translatable' => array('title'), ); } } @@ -228,10 +231,9 @@ function _webform_display_grid($component, $value, $format = 'html') { '#sorted' => TRUE, '#webform_component' => $component, ); - foreach ($questions as $key => $question) { if ($question !== '') { - $element[$question] = array( + $element[$key] = array( '#title' => $question, '#value' => isset($value[$key]) ? $value[$key] : NULL, ); @@ -256,11 +258,11 @@ function theme_webform_display_grid($variables) { foreach ($element['#grid_options'] as $option) { $header[] = array('data' => _webform_filter_xss($option), 'class' => array('checkbox', 'webform-grid-option')); } - foreach (element_children($element) as $key) { + foreach ($element['#grid_questions'] as $question_key => $question) { $row = array(); - $row[] = array('data' => _webform_filter_xss($element[$key]['#title']), 'class' => array('webform-grid-question')); + $row[] = array('data' => _webform_filter_xss($question), 'class' => array('webform-grid-question')); foreach ($element['#grid_options'] as $option_value => $option_label) { - if (strcmp($option_value, $element[$key]['#value']) == 0) { + if (strcmp($element[$question_key]['#value'], $option_value) == 0) { $row[] = array('data' => 'X', 'class' => array('checkbox', 'webform-grid-option')); } else { @@ -399,17 +401,13 @@ function theme_webform_grid($variables) { $rows = array(); $header = array(array('data' => '', 'class' => array('webform-grid-question'))); - $first = TRUE; + // Set the header for the table. + foreach ($element['#options'] as $option) { + $header[] = array('data' => _webform_filter_xss($option), 'class' => array('checkbox', 'webform-grid-option')); + } foreach (element_children($element) as $key) { $question_element = $element[$key]; - // Set the header for the table. - if ($first) { - foreach ($question_element['#options'] as $option) { - $header[] = array('data' => _webform_filter_xss($option), 'class' => array('checkbox', 'webform-grid-option')); - } - $first = FALSE; - } // Create a row with the question title. $row = array(array('data' => _webform_filter_xss($question_element['#title']), 'class' => array('webform-grid-question'))); diff --git a/components/hidden.inc b/components/hidden.inc index 5930da6..4ac823e 100644 --- a/components/hidden.inc +++ b/components/hidden.inc @@ -62,6 +62,7 @@ function _webform_render_hidden($component, $value = NULL, $filter = TRUE) { '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'], '#default_value' => $filter ? _webform_filter_values($component['value']) : $component['value'], '#weight' => $component['weight'], + '#translatable' => array('title'), ); if (isset($value[0])) { diff --git a/components/markup.inc b/components/markup.inc index 064abf5..eb5b470 100644 --- a/components/markup.inc +++ b/components/markup.inc @@ -65,6 +65,7 @@ function _webform_render_markup($component, $value = NULL, $filter = TRUE) { '#format' => $component['extra']['format'], '#theme_wrappers' => array('webform_element'), '#webform_component' => $component, + '#translatable' => array('title', 'markup'), ); // TODO: Remove when #markup becomes available in D7. diff --git a/components/number.inc b/components/number.inc index 13ddbcc..3b67278 100644 --- a/components/number.inc +++ b/components/number.inc @@ -256,6 +256,7 @@ function _webform_render_number($component, $value = NULL, $filter = TRUE) { '#step' => abs($component['extra']['step']), '#integer' => $component['extra']['integer'], '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); // Flip the min and max properties to make min less than max if needed. diff --git a/components/pagebreak.inc b/components/pagebreak.inc index 95c838c..d832c7b 100644 --- a/components/pagebreak.inc +++ b/components/pagebreak.inc @@ -71,6 +71,7 @@ function _webform_display_pagebreak($component, $value = NULL, $format = 'html') '#weight' => $component['weight'], '#format' => $format, '#webform_component' => $component, + '#translatable' => array('title'), ); return $element; } diff --git a/components/select.inc b/components/select.inc index f3ffafe..837b7b0 100644 --- a/components/select.inc +++ b/components/select.inc @@ -271,6 +271,7 @@ function _webform_render_select($component, $value = NULL, $filter = TRUE) { '#theme_wrappers' => array('webform_element'), '#pre_render' => array(), // Needed to disable double-wrapping of radios and checkboxes. '#webform_component' => $component, + '#translatable' => array('title', 'description', 'options'), ); // Convert the user-entered options list into an array. @@ -451,6 +452,7 @@ function _webform_display_select($component, $value, $format = 'html') { return array( '#title' => $component['name'], '#weight' => $component['weight'], + '#options' => _webform_select_options($component), '#theme' => 'webform_display_select', '#theme_wrappers' => $format == 'html' ? array('webform_element') : array('webform_element_text'), '#format' => $format, @@ -505,7 +507,8 @@ function theme_webform_display_select($variables) { $component = $element['#webform_component']; // Convert submitted 'safe' values to un-edited, original form. - $options = _webform_select_options($component, TRUE); + $options = $element['#options']; + $items = array(); if ($component['extra']['multiple']) { diff --git a/components/textarea.inc b/components/textarea.inc index 7523cd9..019e5a4 100644 --- a/components/textarea.inc +++ b/components/textarea.inc @@ -112,6 +112,7 @@ function _webform_render_textarea($component, $value = NULL, $filter = TRUE) { '#resizable' => (bool) $component['extra']['resizable'], // MUST be FALSE to disable. '#theme_wrappers' => array('webform_element'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); if ($component['extra']['disabled']) { diff --git a/components/textfield.inc b/components/textfield.inc index 7c45881..8a2bff1 100644 --- a/components/textfield.inc +++ b/components/textfield.inc @@ -135,6 +135,7 @@ function _webform_render_textfield($component, $value = NULL, $filter = TRUE) { '#attributes' => $component['extra']['attributes'], '#theme_wrappers' => array('webform_element'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); if ($component['extra']['disabled']) { diff --git a/components/time.inc b/components/time.inc index f417020..e69cba0 100644 --- a/components/time.inc +++ b/components/time.inc @@ -99,6 +99,7 @@ function _webform_render_time($component, $value = NULL, $filter = TRUE) { '#theme' => 'webform_time', '#theme_wrappers' => array('webform_element'), '#webform_component' => $component, + '#translatable' => array('title', 'description'), ); // Set the value from Webform if available. diff --git a/includes/webform.components.inc b/includes/webform.components.inc index 18e74bd..f42251d 100644 --- a/includes/webform.components.inc +++ b/includes/webform.components.inc @@ -834,7 +834,6 @@ function webform_component_delete($node, $component) { $child_component = $node->webform['components'][$row->cid]; webform_component_delete($node, $child_component); } - // Post-delete actions. module_invoke_all('webform_component_delete', $component); } @@ -1070,4 +1069,4 @@ function webform_validate_unique($element, $form_state) { form_error($element, t('The value %value has already been submitted once for the %title field. You may have already submitted this form, or you need to use a different value.', array('%value' => $element['#value'], '%title' => $element['#title']))); } } -} +} \ No newline at end of file diff --git a/includes/webform.submissions.inc b/includes/webform.submissions.inc index a377f99..8ea1358 100644 --- a/includes/webform.submissions.inc +++ b/includes/webform.submissions.inc @@ -110,7 +110,7 @@ function webform_submission_insert($node, $submission) { $submission->sid = db_insert('webform_submissions') ->fields(array( - 'nid' => $node->nid, + 'nid' => $node->webform['nid'], 'uid' => $submission->uid, 'submitted' => $submission->submitted, 'remote_addr' => $submission->remote_addr, @@ -124,7 +124,7 @@ function webform_submission_insert($node, $submission) { foreach ($values['value'] as $delta => $value) { db_insert('webform_submitted_data') ->fields(array( - 'nid' => $node->nid, + 'nid' => $node->webform['nid'], 'sid' => $submission->sid, 'cid' => $cid, 'no' => $delta, diff --git a/webform.module b/webform.module index ea75f0a..01e526f 100644 --- a/webform.module +++ b/webform.module @@ -1233,17 +1233,6 @@ function webform_node_prepare($node) { } /** - * Implements hook_node_prepare_translation(). - */ -function webform_node_prepare_translation(&$node) { - // Copy all Webform settings over to translated versions of this node. - if (isset($node->translation_source)) { - $source_node = node_load($node->translation_source->nid); - $node->webform = $source_node->webform; - } -} - -/** * Implements hook_node_load(). */ function webform_node_load($nodes, $types) { @@ -2094,6 +2083,11 @@ function _webform_client_form_add_component($node, $component, $component_value, // This component is display only. $data = empty($submission->data[$cid]['value']) ? NULL : $submission->data[$cid]['value']; if ($display_element = webform_component_invoke($component['type'], 'display', $component, $data, $format)) { + // Allow modules to modify a "display only" webform component. + foreach (module_implements('webform_display_component_alter') as $module) { + $function = $module . '_webform_display_component_alter'; + $function($display_element, $component); + } // The form_builder() function usually adds #parents and #id for us, but // because these are not marked for #input, we need to add them manually. if (!isset($display_element['#parents'])) { @@ -2111,6 +2105,11 @@ function _webform_client_form_add_component($node, $component, $component_value, // Add this user-defined field to the form (with all the values that are always available). $data = isset($submission->data[$cid]['value']) ? $submission->data[$cid]['value'] : NULL; if ($element = webform_component_invoke($component['type'], 'render', $component, $data, $filter)) { + // Allow modules to modify a webform component that is going to be render in a form. + foreach (module_implements('webform_render_component_alter') as $module) { + $function = $module . '_webform_render_component_alter'; + $function($element, $component); + } $parent_fieldset[$component['form_key']] = $element; // Override the value if one already exists in the form state. @@ -2147,6 +2146,7 @@ function _webform_client_form_add_component($node, $component, $component_value, } } + function webform_client_form_validate($form, &$form_state) { $node = node_load($form_state['values']['details']['nid']); $finished = $form_state['values']['details']['finished']; @@ -2403,7 +2403,7 @@ function webform_client_form_submit($form, &$form_state) { } else { // To maintain time and user information, load the existing submission. - $submission = webform_get_submission($node->nid, $sid); + $submission = webform_get_submission($node->webform['nid'], $sid); $submission->is_draft = $is_draft; // Merge with new submission data. The + operator maintains numeric keys. @@ -2441,7 +2441,7 @@ function webform_client_form_submit($form, &$form_state) { // Check if this form is sending an email. if (!$is_draft && !$form_state['values']['details']['finished']) { - $submission = webform_get_submission($node->nid, $sid, TRUE); + $submission = webform_get_submission($node->webform['nid'], $sid, TRUE); webform_submission_send_mail($node, $submission); } @@ -3652,11 +3652,16 @@ function webform_strtotime($date) { } /** - * Wrapper function for tt() if i18nstrings enabled. + * Wrapper function for i18n_string() if i18nstrings enabled. */ function webform_tt($name, $string, $langcode = NULL, $update = FALSE) { - if (function_exists('tt')) { - return tt($name, $string, $langcode, $update); + +if (function_exists('i18n_string')) { + $options = array( + 'langcode' => $langcode, + 'update' => $update, + ); + return i18n_string($name, $string, $options); } else { return $string;