Selaa lähdekoodia

more module updates

Bachir Soussi Chiadmi 9 vuotta sitten
vanhempi
commit
134c8b8338

+ 1 - 1
sites/all/modules/contrib/form/webform_localization/includes/webform_localization.component.sync.inc

@@ -8,7 +8,7 @@
 /**
  * Development sponsored by Riot Games.
  *
- * @author German Martin <gmartin.prg@gmail.com>
+ * @author German Martin <gmartin.php@gmail.com>
  */
 
 /**

+ 208 - 97
sites/all/modules/contrib/form/webform_localization/includes/webform_localization.i18n.inc

@@ -4,13 +4,12 @@
  * @file
  * Webform Localization i18n_string integration.
  */
-
 /**
  * Provides interface with the i18n_string module.
  * Based in patch http://drupal.org/node/245424#comment-5244256
  * by Calin Marian. Further development sponsored by Riot Games.
  *
- * @author German Martin <gmartin.prg@gmail.com>
+ * @author German Martin <gmartin.php@gmail.com>
  */
 
 /**
@@ -80,6 +79,9 @@ function _webform_localization_translate_component(&$element, $component) {
             if ($property == 'markup' && $current_element['#type'] == 'markup') {
               $current_element['#' . $property] = i18n_string($name, $current_element['#' . $property], array('format' => $current_element['#format']));
             }
+            elseif ($property == 'description') {
+              $current_element['#' . $property] = i18n_string($name, $current_element['#' . $property], array('format' => I18N_STRING_FILTER_XSS));
+            }
             else {
               $current_element['#' . $property] = i18n_string($name, $current_element['#' . $property]);
             }
@@ -90,6 +92,76 @@ function _webform_localization_translate_component(&$element, $component) {
   }
 }
 
+/**
+ * Translates the analysis component properties that are translatable.
+ *
+ * These are found in under 'translated_strings' in the 'extra' array of the
+ * component, which is build when the component is inserted / updated, or
+ * when all webform strings are updated from
+ * admin/config/regional/translate/i18n_string.
+ *
+ * @param array $data
+ *   The data array of component results.
+ * @param array $component
+ *   The component.
+ */
+function _webform_localization_translate_analysis_component(&$data, &$component) {
+  if (!isset($component['extra']['translated_strings']) || !is_array($component['extra']['translated_strings'])) {
+    return;
+  }
+  // Attempt to translate select options.
+  if ($component['type'] == 'select') {
+    $item_key_lookup = _webform_localization_string_to_key($component['extra']['items']);
+  }
+  // Attempt to translate grid options / questions.
+  if ($component['type'] == 'grid') {
+    $options_key_lookup = _webform_localization_string_to_key($component['extra']['options']);
+    $questions_key_lookup = _webform_localization_string_to_key($component['extra']['questions']);
+  }
+
+  foreach ($component['extra']['translated_strings'] as $name) {
+    $name_list = explode(':', $name);
+    // Translate component name from title property.
+    if ($name_list[3] == '#title') {
+      $component['name'] = i18n_string($name, $component['name']);
+      continue;
+    }
+    // Translate options for select elements.
+    if ($component['type'] == 'select' && strpos($name_list[3], '-') !== FALSE) {
+      list (, $key) = explode('-', $name_list[3]);
+      if (isset($item_key_lookup[$key])) {
+        foreach ($data['table_rows'] as $index => $row) {
+          if ($row[0] == $item_key_lookup[$key]) {
+            $data['table_rows'][$index][0] = i18n_string($name, $row[0]);
+          }
+        }
+      }
+    }
+    // Translate options / questions for grid elements.
+    if ($component['type'] == 'grid' && $name_list[3] !== '#title') {
+      list (, $key) = explode('-', $name_list[3]);
+      if (strpos($name_list[3], 'grid_options')) {
+        if (isset($options_key_lookup[$key])) {
+          foreach ($data['table_header'] as $index => $row) {
+            if ($row == $options_key_lookup[$key]) {
+              $data['table_header'][$index] = i18n_string($name, $row);
+            }
+          }
+        }
+      }
+      if (strpos($name_list[3], 'grid_questions')) {
+        if (isset($questions_key_lookup[$key])) {
+          foreach ($data['table_rows'] as $index => $row) {
+            if (trim($row[0]) == trim($questions_key_lookup[$key])) {
+              $data['table_rows'][$index][0] = i18n_string($name, $row[0]);
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
 /**
  * Update / create translation source for all the translatable poperties.
  *
@@ -148,36 +220,17 @@ function _webform_localization_component_translation_parse($element, $component)
             // If the child if an array, we translate the elements.
             if (is_array($elem_value)) {
               foreach ($elem_value as $k => $v) {
-                $name = implode(':',
-                                array(
-                                      'webform',
-                                      $component['nid'],
-                                      $component['cid'],
-                                      $property,
-                                      '/-' . $elem_key . '/-',
-                                      $k,
-                                      )
-                                );
+                $name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property, '/-' . $elem_key . '/-', $k);
                 $translated_properies[] = $name;
                 i18n_string($name, $v, array('update' => TRUE));
               }
-              $name = implode(':',
-                              array(
-                                    'webform',
-                                    $component['nid'],
-                                    $component['cid'],
-                                    $property,
-                                    '/-' . $elem_key . '/-',
-                                    )
-                              );
+              $name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property, '/-' . $elem_key . '/-');
               $translated_properies[] = $name;
               i18n_string($name, $elem_key, array('update' => TRUE));
             }
             else {
               // If the child is not an array.
-              $name = implode(':', array('webform',
-                    $component['nid'], $component['cid'],
-                    $property . '-' . $elem_key));
+              $name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property . '-' . $elem_key);
               $translated_properies[] = $name;
               i18n_string($name, $elem_value, array('update' => TRUE));
             }
@@ -188,15 +241,7 @@ function _webform_localization_component_translation_parse($element, $component)
            * If the translatable property is not an array,
            * it can be treated as a string.
            */
-          $name = implode(
-                          ':',
-                          array(
-                                'webform',
-                                $component['nid'],
-                                $component['cid'],
-                                $property
-                                )
-                          );
+          $name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property);
           $translated_properies[] = $name;
           i18n_string($name, $element['#' . $key], array('update' => TRUE));
         }
@@ -211,14 +256,39 @@ function _webform_localization_component_translation_parse($element, $component)
     $element[$child]['#parents'][] = $child;
     // Add the translated propertied to the list.
     $translated_properies = array_merge(
-      $translated_properies,
-      _webform_localization_component_translation_parse($element[$child], $component)
-      );
+            $translated_properies,
+            _webform_localization_component_translation_parse($element[$child], $component)
+    );
   }
 
   return $translated_properies;
 }
 
+/**
+ * Utility function to create i18n string name.
+ *
+ * Additional arguments can be passed to add more depth to context
+ *
+ * @param int $node_identifier
+ *   webform nid
+ *
+ * @return string
+ *   i18n string name grouped by nid or uuid if module is available
+ */
+function webform_localization_i18n_string_name($node_identifier) {
+  if (module_exists('uuid')) {
+    $node_identifier = current(entity_get_uuid_by_id('node', array($node_identifier)));
+  }
+  $name = array('webform', $node_identifier);
+  $args = func_get_args();
+  // Remove $node_identifier from args
+  array_shift($args);
+  foreach ($args as $arg) {
+    $name[] = $arg;
+  }
+  return implode(':', $name);
+}
+
 /**
  * Delete translation source for all the translatable poperties
  *
@@ -263,18 +333,18 @@ function webform_localization_component_delete_translation_strings($component) {
  */
 function webform_localization_update_translation_strings($properties) {
   if (!empty($properties['confirmation']['value'])) {
-    $name = implode(':', array('webform', $properties['nid'], 'confirmation'));
+    $name = webform_localization_i18n_string_name($properties['nid'], 'confirmation');
     i18n_string($name, $properties['confirmation']['value'], array('update' => TRUE));
   }
   if (!empty($properties['submit_text'])) {
-    $name = implode(':', array('webform', $properties['nid'], 'submit_text'));
+    $name = webform_localization_i18n_string_name($properties['nid'], 'submit_text');
     i18n_string($name, $properties['submit_text'], array('update' => TRUE));
   }
 
   // Allow to translate the redirect url if it's not set to none or the
   // default confirmation page.
   if (!in_array($properties['redirect_url'], array('<confirmation>', '<none>'))) {
-    $name = implode(':', array('webform', $properties['nid'], 'redirect_url'));
+    $name = webform_localization_i18n_string_name($properties['nid'], 'redirect_url');
     i18n_string($name, $properties['redirect_url'], array('update' => TRUE));
   }
 }
@@ -287,19 +357,12 @@ function webform_localization_update_translation_strings($properties) {
  */
 function webform_localization_translate_strings(&$node, $update = FALSE) {
   $option = array('update' => $update, 'sanitize' => FALSE);
-  $name = implode(':', array('webform',
-        $node->webform['nid'],
-        'confirmation'));
+  $name = webform_localization_i18n_string_name($node->webform['nid'], 'confirmation');
   $node->webform['confirmation'] = i18n_string(
           $name,
           $node->webform['confirmation'],
           $option);
-  $name = implode(
-          ':',
-          array(
-            'webform',
-            $node->webform['nid'],
-            'submit_text'));
+  $name = webform_localization_i18n_string_name($node->webform['nid'], 'submit_text');
   $node->webform['submit_text'] = i18n_string(
           $name,
           $node->webform['submit_text'],
@@ -308,7 +371,7 @@ function webform_localization_translate_strings(&$node, $update = FALSE) {
   // Allow to translate the redirect url if it's not set to none or the
   // default confirmation page.
   if (!in_array($node->webform['redirect_url'], array('<confirmation>', '<none>'))) {
-    $name = implode(':', array('webform', $node->webform['nid'], 'redirect_url'));
+    $name = webform_localization_i18n_string_name($node->webform['nid'], 'redirect_url');
     $node->webform['redirect_url'] = i18n_string($name, $node->webform['redirect_url'], $option);
   }
 }
@@ -323,29 +386,20 @@ function webform_localization_emails_update_translation_string($properties) {
   $nid = $properties['node']->webform['nid'];
   $eid = $properties['eid'];
   if (!empty($properties['subject_custom'])) {
-    $name = implode(':',
-            array('webform',
-              $nid,
-              'email',
-              $eid,
-              'subject_custom'));
+    $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'subject_custom');
     i18n_string($name, $properties['subject_custom'], array('update' => TRUE));
   }
   // Allow to translate the mail recipients if not based on a component.
   if (!empty($properties['email']) && !is_numeric($properties['email'])) {
-    $name = implode(':', array('webform', $nid, 'email', $eid, 'email'));
+    $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'email');
     i18n_string($name, $properties['email'], array('update' => TRUE));
   }
   if (!empty($properties['from_name_custom'])) {
-    $name = implode(':', array('webform',
-          $nid,
-          'email',
-          $eid,
-          'from_name_custom'));
+    $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'from_name_custom');
     i18n_string($name, $properties['from_name_custom'], array('update' => TRUE));
   }
   if (!empty($properties['template'])) {
-    $name = implode(':', array('webform', $nid, 'email', $eid, 'template'));
+    $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'template');
     i18n_string($name, $properties['template'], array('update' => TRUE));
   }
 }
@@ -362,28 +416,20 @@ function webform_localization_emails_translation_string_refresh($emails, $nid) {
   foreach ($emails as $email) {
     $eid = $email['eid'];
     if (!empty($email['subject']) && $email['subject'] != 'default') {
-      $name = implode(':', array('webform',
-            $nid,
-            'email',
-            $eid,
-            'subject_custom'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'subject_custom');
       i18n_string($name, $email['subject'], array('update' => TRUE));
     }
     // Allow to translate the mail recipients if not based on a component.
     if (!empty($email['email']) && !is_numeric($email['email'])) {
-      $name = implode(':', array('webform', $nid, 'email', $eid, 'email'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'email');
       i18n_string($name, $email['email'], array('update' => TRUE));
     }
     if (!empty($email['from_name']) && $email['from_name'] != 'default') {
-      $name = implode(':', array('webform',
-            $nid,
-            'email',
-            $eid,
-            'from_name_custom'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'from_name_custom');
       i18n_string($name, $email['from_name'], array('update' => TRUE));
     }
     if (!empty($email['template']) && $email['template'] != 'default') {
-      $name = implode(':', array('webform', $nid, 'email', $eid, 'template'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'template');
       i18n_string($name, $email['template'], array('update' => TRUE));
     }
   }
@@ -399,28 +445,20 @@ function webform_localization_email_translate_strings(&$node) {
   $nid = $node->webform['nid'];
   foreach ($node->webform['emails'] as $eid => &$email) {
     if (!empty($email['subject']) && $email['subject'] != 'default') {
-      $name = implode(':', array('webform',
-            $nid,
-            'email',
-            $eid,
-            'subject_custom'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'subject_custom');
       $email['subject'] = i18n_string($name, $email['subject']);
     }
     // Allow to translate the mail recipients if not based on a component.
     if (!empty($email['email']) && !is_numeric($email['email'])) {
-      $name = implode(':', array('webform', $nid, 'email', $eid, 'email'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'email');
       $email['email'] = i18n_string($name, $email['email']);
     }
     if (!empty($email['from_name']) && $email['from_name'] != 'default') {
-      $name = implode(':', array('webform',
-            $nid,
-            'email',
-            $eid,
-            'from_name_custom'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'from_name_custom');
       $email['from_name'] = i18n_string($name, $email['from_name']);
     }
     if (!empty($email['template']) && $email['template'] != 'default') {
-      $name = implode(':', array('webform', $nid, 'email', $eid, 'template'));
+      $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'template');
       $email['template'] = i18n_string($name, $email['template']);
     }
   }
@@ -435,17 +473,11 @@ function webform_localization_email_translate_strings(&$node) {
  *   A node Id.
  */
 function webform_localization_emails_delete_translation_string($eid, $nid) {
-  $name = implode(':', array('webform', $nid, 'email', $eid, 'subject_custom'));
+  $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'subject_custom');
   i18n_string_remove($name);
-  $name = implode(
-          ':',
-          array('webform',
-            $nid,
-            'email',
-            $eid,
-            'from_name_custom'));
+  $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'from_name_custom');
   i18n_string_remove($name);
-  $name = implode(':', array('webform', $nid, 'email', $eid, 'template'));
+  $name = webform_localization_i18n_string_name($nid, 'email', $eid, 'template');
   i18n_string_remove($name);
 }
 
@@ -456,15 +488,76 @@ function webform_localization_emails_delete_translation_string($eid, $nid) {
  *   A node object.
  */
 function webform_localization_delete_translate_strings($node) {
-  $name = implode(':', array('webform', $node->webform['nid'], 'confirmation'));
+  $name = webform_localization_i18n_string_name($node->webform['nid'], 'confirmation');
   i18n_string_remove($name);
-  $name = implode(':', array('webform', $node->webform['nid'], 'submit_text'));
+  $name = webform_localization_i18n_string_name($node->webform['nid'], 'submit_text');
   i18n_string_remove($name);
   foreach ($node->webform['emails'] as $eid => $value) {
     webform_localization_emails_delete_translation_string($eid, $node->nid);
   }
 }
 
+/**
+ * Update i18n string contexts if uuid module is enabled/disabled.
+ *
+ */
+function webform_localization_uuid_update_strings($disabling_uuid = FALSE) {
+  module_load_install('i18n_string');
+  $old_ids = db_query('SELECT distinct type FROM {i18n_string} WHERE textgroup = :webform', array(
+        ':webform' => 'webform'
+      ))->fetchCol();
+  variable_set('webform_localization_using_uuid', !$disabling_uuid);
+  if (empty($old_ids)) {
+    return;
+  }
+  if (!$disabling_uuid) {
+    $old_context_ids = entity_get_uuid_by_id('node', array($old_ids));
+  }
+  else {
+    // entity_get_id_by_uuid() do not work properly on hook_disable.
+    $old_context_ids = webform_localization_get_id_by_uuid('node', array($old_ids));
+  }
+
+  foreach ($old_context_ids as $old_id => $new_id) {
+    $old_context = 'webform:' . $old_id . ':*';
+    $new_context = 'webform:' . $new_id . ':*';
+    i18n_string_install_update_context($old_context, $new_context);
+  }
+}
+
+/**
+ * Helper function that retrieves entity IDs by their UUIDs.
+ *
+ *
+ * @param $entity_type
+ *   The entity type we should be dealing with.
+ * @param $uuids
+ *   An array of UUIDs for which we should find their entity IDs. If $revision
+ *   is TRUE this should be revision UUIDs instead.
+ * @return
+ *   Array of entity IDs keyed by their UUIDs. If $revision is TRUE revision
+ *   IDs and UUIDs are returned instead.
+ */
+function webform_localization_get_id_by_uuid($entity_type, $uuids) {
+  if (empty($uuids)) {
+    return array();
+  }
+  $info = entity_get_info($entity_type);
+  $table = $info['base table'];
+  $id_key = $info['entity keys']['id'];
+
+  // The uuid key is not available at hook_disable.
+  $core_info = uuid_get_core_entity_info();
+  $uuid_key = $core_info['node']['entity keys']['uuid'];
+
+  // Get all UUIDs in one query.
+  return db_select($table, 't')
+      ->fields('t', array($uuid_key, $id_key))
+      ->condition($uuid_key, array_values($uuids), 'IN')
+      ->execute()
+      ->fetchAllKeyed();
+}
+
 /**
  * Helper function to replace an array key and its content.
  *
@@ -486,3 +579,21 @@ function _webform_localization_array_key_replace(&$array, $old_key, $new_key) {
   }
   $array = array_combine($keys, $values);
 }
+
+/**
+ * Helper function to convert select / grid strings to array.
+ *
+ * @param $string_array
+ *   Array To process.
+ *
+ */
+function _webform_localization_string_to_key($string_array) {
+  $key_array = array();
+  $items = explode("\n", trim($string_array));
+  foreach ($items as $item) {
+    $item_data = explode('|', $item);
+    $key_array[$item_data[0]] = $item_data[1];
+  }
+  return $key_array;
+}
+

+ 1 - 1
sites/all/modules/contrib/form/webform_localization/includes/webform_localization.sync.inc

@@ -8,7 +8,7 @@
 /**
  * Development sponsored by Riot Games.
  *
- * @author German Martin <gmartin.prg@gmail.com>
+ * @author German Martin <gmartin.php@gmail.com>
  */
 
 /**

+ 237 - 160
sites/all/modules/contrib/form/webform_localization/tests/webform_localization.test

@@ -4,31 +4,23 @@
  * @file
  * Webform localization module tests.
  */
-class WebformLocalizationTestCase extends DrupalWebTestCase {
+class WebformLocalizationWebTestCase extends DrupalWebTestCase {
 
+  // Webform test class instance.
   public $wtc;
+  // Users.
   public $admin_user;
   public $translator;
   public $normal_user;
 
-  /**
-   * Implements getInfo().
-   */
-  public static function getInfo() {
-    return array(
-      'name' => t('Webform Localization'),
-      'description' => t('Webform localization features test.'),
-      'group' => t('Webform'),
-    );
-  }
-
   /**
    * Implements setUp().
    */
-  function setUp() {
-    parent::setUp('locale', 'translation', 'translation_test', 'i18n', 'i18n_string', 'webform', 'webform_localization');
+  function setUp($modules = array()) {
+    $modules = array_merge($modules, array('locale', 'webform', 'webform_localization'));
+    parent::setUp($modules);
 
-    // We load webform test class to reuse webform and components creation functions
+    // We load webform test class to reuse webform and components creation functions.
     module_load_include('test', 'webform', 'tests/webform');
     $this->wtc = new WebformTestCase;
 
@@ -38,17 +30,19 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
           'access all webform results',
           'edit all webform submissions',
           'delete all webform submissions',
-          'translate interface'));
+          'translate interface',
+          'translate user-defined strings'));
 
     $this->translator = $this->drupalCreateUser(array('translate content',
           'create webform content',
           'edit any webform content',
           'access all webform results',
-          'translate interface'));
+          'translate interface',
+          'translate user-defined strings'));
 
     $this->normal_user = $this->drupalCreateUser(array('access content', 'edit own webform submissions'));
 
-    // Fix for reuse of webform test class
+    // Fix for reuse of webform test class.
     $this->wtc->webform_users['admin'] = $this->admin_user;
     $this->wtc->webform_users['admin']->profile_gender = array('Female', 'Male');
 
@@ -59,112 +53,15 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
     $this->addLanguage('es');
     $this->addLanguage('de');
 
-    // Enable URL language detection and selection
+    // Enable URL language detection and selection.
     $edit = array('language[enabled][locale-url]' => TRUE);
     $this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
-    $this->assertRaw(t('Language negotiation configuration saved.'), t('URL language detection enabled.'));
+    $this->assertRaw(t('Language negotiation configuration saved.'), 'URL language detection enabled.');
     drupal_static_reset('locale_url_outbound_alter');
-
-    // Set "Webform" content type to use multilingual support with translation.
-    $this->drupalGet('admin/structure/types/manage/webform');
-    $edit = array();
-    $edit['language_content_type'] = 2;
-    $this->drupalPost('admin/structure/types/manage/webform', $edit, t('Save content type'));
-    $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Webform')), t('Webform content type has been updated.'));
-  }
-
-  /**
-   * Test creating a webform and enabling localization by string translation
-   */
-  function testWebformLocalizationConfig() {
-    $this->drupalLogin($this->admin_user);
-    /**
-     * Create the Webform test node, and enable
-     * localization by string translation feature
-     */
-    $node = $this->createWebformForm();
-
-    // Submit translation in Spanish.
-    $node_translation_title = 'Webform title in Spanish';
-    $node_translation_body = 'Content in Spanish';
-    $node_translation1 = $this->createWebformTranslation($node, $node_translation_title, $node_translation_body, 'es');
-
-    // Submit translation in German.
-    $node_translation_title = 'Webform title in German';
-    $node_translation_body = 'Content in German';
-    $node_translation2 = $this->createWebformTranslation($node, $node_translation_title, $node_translation_body, 'de');
-
-    /**
-     * Enables localization by string translation and reuse the single webform
-     * across the translation set.
-     */
-    $edit = array();
-    $edit['expose_strings'] = TRUE;
-    $edit['single_webform'] = TRUE;
-    $this->drupalPost('node/' . $node->nid . '/webform/configure', $edit, t('Save configuration'));
-    $this->assertRaw(t('The form settings have been updated.'), t('Webform string translation and single webform enabled.'));
-
-    // Checks for webform components in the Spanish node
-    $this->drupalGet('es/node/' . $node_translation1->nid);
-    foreach ($node->webform['components'] as $key => $value) {
-      if ($value['name'] == 'Hidden') {
-        $this->assertNoRaw($value['name'], t('The %c webform component is not present.', array('%c' => $value['name'])), 'Spanish Webform translation');
-        CONTINUE;
-      }
-      $this->assertRaw($value['name'], t('The %c webform component is present.', array('%c' => $value['name'])), 'Spanish Webform translation');
-    }
-
-    // Checks for webform components in the Deutsch node
-    $this->drupalGet('de/node/' . $node_translation2->nid);
-    foreach ($node->webform['components'] as $key => $value) {
-      if ($value['name'] == 'Hidden') {
-        $this->assertNoRaw($value['name'], t('The %c webform component is not present.', array('%c' => $value['name'])), 'German Webform translation');
-        CONTINUE;
-      }
-      $this->assertRaw($value['name'], t('The %c webform component is present.', array('%c' => $value['name'])), 'Deutsch Webform translation');
-    }
-
-    // Refresh webform strings
-    $edit = array();
-    $edit['groups[webform]'] = 'webform';
-    $this->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
-
-    // Select webform localization options that match this node ID.
-    $options = db_select('locales_source')
-            ->fields('locales_source')
-            ->condition('textgroup', 'webform', '=')
-            ->execute()
-            ->fetchAllAssoc('lid', PDO::FETCH_ASSOC);
-
-    // $refresh_node = node_load($node->nid,$node->vid, TRUE);
-    // Translates webform components
-    $translations = array();
-    foreach ($options as $key => $value) {
-      $name = $value['source'];
-      $translations['de'] = 'de:' . $name;
-      $translations['es'] = 'es:' . $name;
-      $this->createStringTranslation('webform', $name, $translations);
-    }
-    $this->drupalGet('es/node/' . $node_translation1->nid);
-    foreach ($options as $key => $value) {
-      $name = $value['source'];
-      $translation = 'es:' . $name;
-      $this->assertRaw($translation, t('%c translation is present.', array('%c' => $name)), 'Spanish Webform translation');
-    }
-    $this->drupalGet('de/node/' . $node_translation2->nid);
-    foreach ($options as $key => $value) {
-      $name = $value['source'];
-      $translation = 'de:' . $name;
-      $this->assertRaw($translation, t('%c translation is present.', array('%c' => $name)), 'Deutsch Webform translation');
-    }
-    /**
-     * @todo
-     * Pending to Fix deveral fails and exceptions
-     */
   }
 
   /**
-   * Create a webform node with test components
+   * Create a webform node with test components.
    */
   function createWebformForm() {
     if (isset($this->_webform_node)) {
@@ -183,7 +80,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
       'translate' => '0',
       'title' => 'Webform title in english',
       'body' => array('en' => array(
-                array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
+          array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
                                  Sed tempor. Sed vitae tellus. Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non lacus vitae ipsum viverra
                                  pretium. Phasellus massa. Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce consectetuer luctus ipsum.
                                  Vestibulum nunc. Suspendisse dignissim adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum nibh,
@@ -191,7 +88,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
                                  retium quis, dapibus sed, varius non, lectus. Proin a quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus
                                  volutpat urna, ut fermentum neque mi egestas dolor.'))),
       'teaser' => array('en' => array(
-                  array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
+          array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
                                    Sed tempor. Sed vitae tellus. Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non lacus vitae ipsum
                                    viverra pretium. Phasellus massa. Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce consectetuer luctus
                                    ipsum. Vestibulum nunc. Suspendisse dignissim adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum nibh,
@@ -199,23 +96,22 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
       'log' => '',
       'format' => '1',
       'webform' => array(
-        'confirmation' => 'Thanks!',
-        'confirmation_format' => filter_default_format(),
-        'redirect_url' => '<confirmation>',
-        'teaser' => '0',
-        'allow_draft' => '1',
-        'submit_text' => '',
-        'submit_limit' => '-1',
-        'submit_interval' => '-1',
-        'submit_notice' => '1',
-        'roles' => array('1', '2'),
-        'components' => array(),
-        'emails' => array(),
-      ),
+    'confirmation' => 'Thanks!',
+      ) + webform_node_defaults(),
     );
+    $components = $this->wtc->testWebformComponents();
+
+    /*
+     *  @todo : We need further debug to find how to support
+     *  this components or why are they breaking everything
+     */
+    unset($components['select_no_default_zero']);
+    unset($components['radios_zero']);
+    unset($components['select_zero']);
+    unset($components['select_optgroup']);
 
     $cid = 0;
-    foreach ($this->wtc->testWebformComponents() as $key => $component_info) {
+    foreach ($components as $key => $component_info) {
       $cid++;
       $settings['webform']['components'][$cid] = $component_info['component'];
       $settings['webform']['components'][$cid]['cid'] = $cid;
@@ -247,10 +143,10 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
       // Make sure we are not using a stale list.
       drupal_static_reset('language_list');
       $languages = language_list('language');
-      $this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
+      $this->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.');
 
       if (array_key_exists($language_code, $languages)) {
-        $this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), t('Language has been created.'));
+        $this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), 'Language has been created.');
       }
     }
     elseif ($this->xpath('//input[@type="checkbox" and @name=:name and @checked="checked"]', array(':name' => 'enabled[' . $language_code . ']'))) {
@@ -261,7 +157,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
       // It's installed but not enabled. Enable it.
       $this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed.');
       $this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
-      $this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
+      $this->assertRaw(t('Configuration saved.'), 'Language successfully enabled.');
     }
   }
 
@@ -288,14 +184,14 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
 
     $edit = array();
     $edit["title"] = $title;
-    $edit[$body_key] = $body;
+    //$edit[$body_key] = $body;
     $this->drupalPost(NULL, $edit, t('Save'));
-    $this->assertRaw(t('Webform %title has been created.', array('%title' => $title)), t('Translation created.'));
+    $this->assertRaw(t('Webform %title has been created.', array('%title' => $title)), 'Translation created.');
 
     // Check to make sure that translation was successful.
     $translation = $this->drupalGetNodeByTitle($title);
-    $this->assertTrue($translation, t('Node found in database.'));
-    $this->assertTrue($translation->tnid == $node->nid, t('Translation set id correctly stored.'));
+    $this->assertTrue($translation, 'Node found in database.');
+    $this->assertTrue($translation->tnid == $node->nid, 'Translation set id correctly stored.');
 
     return $translation;
   }
@@ -307,14 +203,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
    *   Optional array of langcode => translation. If not present, it will be generated.
    */
   function createStringTranslation($textgroup, $name, $translations = NULL) {
-    // Generate translations if not found, they will be the same length as source string
-    if (!$translations) {
-      $length = drupal_strlen($name);
-      foreach ($this->getOtherLanguages() as $language) {
-        $translations[$language->language] = $this->randomName($length);
-      }
-    }
-    //$this->drupalLogin($this->translator);
+
     // This is the language indicator on the translation search screen for
     // untranslated strings. Copied straight from locale.inc.
     $language_indicator = "<em class=\"locale-untranslated\">";
@@ -329,32 +218,43 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
     // assertText() seems to remove the input field where $name always could be
     // found, so this is not a false assert. See how assertNoText succeeds
     // later.
-    //$this->assertNoUniqueText();
-    $this->assertText(check_plain($name), t('Search found the name.'));
-    $this->assertRaw($language_indicator, t('Name is untranslated.'));
+    $this->assertText(check_plain($name), 'Search found the name.');
+    $this->assertRaw($language_indicator, 'Name is untranslated.');
 
-    // Is not always the only result, iif there is more than one click the first.
+    // Is not always the only result, if there is more than one click the first.
     if ($this->countString(check_plain($name)) > 1) {
       $this->clickLink(t('edit'), 0);
     }
-    else
+    else {
       $this->clickLink(t('edit'));
+    }
 
     // We save the lid from the path.
     $matches = array();
     preg_match('!admin/config/regional/translate/edit/(\d+)!', $this->getUrl(), $matches);
     $lid = $matches[1];
-    // No t() here, it's surely not translated yet.
-    $this->assertRaw(check_plain($name), t($name . ' name found on edit screen.'));
+
+    /*
+     * Using check_plain() and wordwrap() as i18n_string_locale_translate_edit_form().
+     * Assert fails otherwise.
+     */
+    $this->assertRaw(check_plain(wordwrap($name, 0)), t($name . ' name found on edit screen.'));
     foreach ($translations as $langcode => $translation) {
       $edit["translations[$langcode]"] = $translation;
     }
     $this->drupalPost(NULL, $edit, t('Save translations'));
-    $this->assertText(t('The string has been saved.'), t('The string has been saved.'));
-    $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
+    $this->assertText(t('The string has been saved.'), 'The string has been saved.');
+    $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
+    $search = array(
+      'string' => $name,
+      'language' => 'all',
+      'translation' => 'translated',
+      'group' => $textgroup,
+    );
     $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
-    // The indicator should not be here.
-    //$this->assertNoRaw($language_indicator, t('String is translated.'));
+    $this->assertText(check_plain($name), 'Search found the name.');
+    $this->assertNoRaw($language_indicator, 'Name is translated.');
+
     return $translations;
   }
 
@@ -375,3 +275,180 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
   }
 
 }
+
+class WebformLocalizationStringTranslationTestCase extends WebformLocalizationWebTestCase {
+
+  /**
+   * Implements getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Webform Localization',
+      'description' => 'Webform localization String Translations Tests.',
+      'group' => 'Webform Localization',
+    );
+  }
+
+  /**
+   * Set up test.
+   */
+  public function setUp($modules = array()) {
+    parent::setUp(array('translation', 'i18n', 'i18n_string'));
+
+    // Set "Webform" content type to use multilingual support with translation.
+    $this->drupalGet('admin/structure/types/manage/webform');
+    $edit = array();
+    $edit['language_content_type'] = 2;
+    $this->drupalPost('admin/structure/types/manage/webform', $edit, t('Save content type'));
+    $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Webform')), 'Webform content type has been updated.');
+  }
+
+  /**
+   * Test creating a webform and enabling localization by string translation
+   */
+  function testWebformLocalizationStringTranslation() {
+    $this->drupalLogin($this->admin_user);
+    /**
+     * Create the Webform test node, and enable
+     * localization by string translation feature
+     */
+    $node = $this->createWebformForm();
+
+    // Submit translation in Spanish.
+    $node_translation_title = 'Webform title in Spanish';
+    $node_translation_body = 'Content in Spanish';
+    $node_translation1 = $this->createWebformTranslation($node, $node_translation_title, $node_translation_body, 'es');
+
+    // Submit translation in German.
+    $node_translation_title = 'Webform title in German';
+    $node_translation_body = 'Content in German';
+    $node_translation2 = $this->createWebformTranslation($node, $node_translation_title, $node_translation_body, 'de');
+
+    /**
+     * Enables localization by string translation and reuse the single webform
+     * across the translation set.
+     */
+    $edit = array();
+    $edit['expose_strings'] = TRUE;
+    $edit['single_webform'] = TRUE;
+    $this->drupalPost('node/' . $node->nid . '/webform/configure', $edit, t('Save configuration'));
+    $this->assertRaw(t('The form settings have been updated.'), 'Webform string translation and single webform enabled.');
+
+    // Checks for webform components in the Spanish node
+    $this->drupalGet('es/node/' . $node_translation1->nid);
+    foreach ($node->webform['components'] as $key => $value) {
+      if ($value['name'] == 'Hidden') {
+        $this->assertNoRaw($value['name'], format_string('The %c webform component is not present.', array('%c' => $value['name'])), 'Spanish Webform translation');
+        CONTINUE;
+      }
+      $this->assertRaw($value['name'], format_string('The %c webform component is present.', array('%c' => $value['name'])), 'Spanish Webform translation');
+    }
+
+    // Checks for webform components in the Deutsch node
+    $this->drupalGet('de/node/' . $node_translation2->nid);
+    foreach ($node->webform['components'] as $key => $value) {
+      if ($value['name'] == 'Hidden') {
+        $this->assertNoRaw($value['name'], format_string('The %c webform component is not present.', array('%c' => $value['name'])), 'German Webform translation');
+        CONTINUE;
+      }
+      $this->assertRaw($value['name'], format_string('The %c webform component is present.', array('%c' => $value['name'])), 'Deutsch Webform translation');
+    }
+
+    // Refresh webform strings
+    $edit = array();
+    $edit['groups[webform]'] = 'webform';
+    $this->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
+
+    // Select webform localization options that match this node ID.
+    $options = db_select('locales_source')
+            ->fields('locales_source')
+            ->condition('textgroup', 'webform', '=')
+            ->execute()
+            ->fetchAllAssoc('lid', PDO::FETCH_ASSOC);
+
+    // Translates webform components.
+    $translations = array();
+    $extra_translations = array();
+    foreach ($options as $key => $value) {
+      $name = $value['source'];
+      $translations['de'] = 'de:' . $name;
+      $translations['es'] = 'es:' . $name;
+      $this->createStringTranslation('webform', $name, $translations);
+      // We take out confirmation to check after submit.
+      if (strpos($value['location'], 'confirmation')) {
+        $extra_translations['confirmation'] = $value['source'];
+        unset($options[$key]);
+      }
+    }
+    $this->drupalGet('es/node/' . $node_translation1->nid);
+    foreach ($options as $key => $value) {
+      list(, $cid, ) = explode(':', $value['context']);
+      $component = $node->webform['components'][$cid];
+      $name = $value['source'];
+      $translation = 'es:' . $name;
+      if ($name == 'Hidden') {
+        CONTINUE;
+      }
+      $this->assertRaw($translation, format_string('%c translation is present.', array('%c' => $name)), 'Spanish Webform translation');
+    }
+    $this->drupalGet('de/node/' . $node_translation2->nid);
+    foreach ($options as $key => $value) {
+      $name = $value['source'];
+      $translation = 'de:' . $name;
+      if ($name == 'Hidden') {
+        CONTINUE;
+      }
+      $this->assertRaw($translation, format_string('%c translation is present.', array('%c' => $name)), 'Deutsch Webform translation');
+    }
+  }
+
+}
+
+class WebformLocalizationApiTestCase extends WebformLocalizationWebTestCase {
+
+  /**
+   * Test info.
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Test Webform Localization API.',
+      'description' => 'Test webform and webform localization interaction at API level.',
+      'group' => 'Webform Localization',
+    );
+  }
+
+  /**
+   * Set up test.
+   */
+  public function setUp($modules = array()) {
+    parent::setUp(array('translation', 'i18n', 'i18n_string'));
+
+    // Set "Webform" content type to use multilingual support with translation.
+    $this->drupalGet('admin/structure/types/manage/webform');
+    $edit = array();
+    $edit['language_content_type'] = 2;
+    $this->drupalPost('admin/structure/types/manage/webform', $edit, t('Save content type'));
+    $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Webform')), 'Webform content type has been updated.');
+  }
+
+  /**
+   * Test submissions API function with webform localization presence.
+   */
+  function testWebformLocalizationApi() {
+    $this->drupalLogin($this->admin_user);
+    $node = $this->createWebformForm();
+    /**
+     * Enables localization by string translation and reuse the single webform
+     * across the translation set.
+     */
+    $edit = array();
+    $edit['expose_strings'] = TRUE;
+    $edit['single_webform'] = TRUE;
+    $this->drupalPost('node/' . $node->nid . '/webform/configure', $edit, t('Save configuration'));
+    $this->assertRaw(t('The form settings have been updated.'), 'Webform string translation and single webform enabled.');
+
+    module_load_include('inc', 'webform', 'includes/webform.submissions');
+    $this->assertFalse(webform_get_submissions($node->nid), "Function webform_get_submission($node->nid,1000) work correctly with empty submissions.");
+  }
+
+}

+ 2 - 2
sites/all/modules/contrib/form/webform_localization/webform_localization.info

@@ -8,9 +8,9 @@ package = Webform
 
 files[] = tests/webform_localization.test
 
-; Information added by drupal.org packaging script on 2013-09-11
+; Information added by Drupal.org packaging script on 2014-03-28
 version = "7.x-4.x-dev"
 core = "7.x"
 project = "webform_localization"
-datestamp = "1378901956"
+datestamp = "1396049366"
 

+ 2 - 0
sites/all/modules/contrib/form/webform_localization/webform_localization.install

@@ -22,6 +22,7 @@ function webform_localization_install() {
     'not null' => TRUE,
     'default' => '',
   ));
+  variable_set('webform_localization_using_uuid', module_exists('uuid'));
 }
 
 /**
@@ -29,6 +30,7 @@ function webform_localization_install() {
  */
 function webform_localization_uninstall() {
   db_drop_field('webform_submissions', 'language');
+  variable_del('webform_localization_using_uuid');
 }
 
 /**

+ 129 - 17
sites/all/modules/contrib/form/webform_localization/webform_localization.module

@@ -12,7 +12,7 @@
  *
  * Further development sponsored by Riot Games.
  *
- * @author German Martin <gmartin.prg@gmail.com>
+ * @author German Martin <gmartin.php@gmail.com>
  */
 
 /**
@@ -48,19 +48,27 @@ function webform_localization_i18n_string_info() {
 }
 
 /**
- * Update / create / delete translation source for components
+ * Update / create / delete translation source for components.
  *
  * Refresh callback that regenerates all the translatable poperties of the
- * components of the matching webforms configuration
+ * components of the matching webforms configuration.
  */
 function webform_localization_i18n_string_refresh() {
+
+  module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
+
+  // In case updating before UUID support.
+  if (module_exists('uuid') && !variable_get('webform_localization_using_uuid', FALSE)) {
+    webform_localization_uuid_update_strings(FALSE);
+  }
+
   // Get components configured as translatable.
   $query = db_select('webform_component', 'wc');
   $query->fields('wc');
   $query->condition('wl.expose_strings', 0, '>');
   $query->innerJoin('webform_localization', 'wl', 'wc.nid = wl.nid');
   $components = $query->execute()->fetchAll();
-  module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
+
   foreach ($components as $component) {
     $component = (array) $component;
     $component['extra'] = unserialize($component['extra']);
@@ -204,9 +212,9 @@ function webform_localization_node_view($node, $view_mode) {
   $query = db_select('webform', 'w');
   $query->innerJoin('webform_localization', 'wl', 'w.nid = wl.nid');
   $query->fields('w', array('nid'));
-  $query->condition('wl.single_webform', 0, '!=');
+  $query->condition('wl.single_webform', 0, '<>');
   $query->condition('wl.single_webform', $node->tnid, '=');
-  $query->condition('w.nid', $node->nid, '!=');
+  $query->condition('w.nid', $node->nid, '<>');
   $result = $query->execute()->fetchField();
 
   if ($result) {
@@ -217,10 +225,18 @@ function webform_localization_node_view($node, $view_mode) {
      * independent function to reuse.
      */
     $source_node = node_load($result);
-    // We replace the webform with the node translation source
+    // We replace the webform with the node translation source.
     $node->webform = $source_node->webform;
-    // Call node view implementation to update the $node->content
+
+    // This fool webform_node_view to avoid errors with drafts in between pages.
+    $translation_nid = $node->nid;
+    if (($node->webform['allow_draft'] || $node->webform['auto_save']) && $user->uid != 0) {
+      $node->nid = $source_node->nid;
+    }
+    // Call node view implementation to update the $node->content.
     webform_node_view($node, $view_mode);
+    // Reset the nid if we used the drafts fix.
+    $node->nid = $translation_nid;
   }
 }
 
@@ -238,7 +254,7 @@ function webform_localization_node_load($nodes, $types) {
     $wl_options = webform_localization_get_config($nid);
     if ($wl_options['expose_strings']) {
       module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
-      // Translate custom strings
+      // Translate custom strings.
       webform_localization_translate_strings($node);
       webform_localization_email_translate_strings($node);
     }
@@ -268,6 +284,9 @@ function webform_localization_webform_submission_insert($node, $submission) {
  * Implements hook_webform_submission_load().
  */
 function webform_localization_webform_submission_load(&$submissions) {
+  if(empty($submissions)) {
+      return;
+  }
   $query = db_select('webform_submissions', 's');
   $query->fields('s', array('language', 'sid'));
   $query->condition('s.sid', array_keys($submissions), 'IN');
@@ -282,7 +301,7 @@ function webform_localization_webform_submission_load(&$submissions) {
  */
 function webform_localization_node_delete($node) {
   if (!in_array($node->type, webform_variable_get('webform_node_types'))
-    || empty($node->webform['components'])) {
+      || empty($node->webform['components'])) {
     return;
   }
   module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
@@ -318,14 +337,40 @@ function webform_localization_webform_component_display_alter(&$display_element,
   }
 }
 
+/**
+ * Implements hook_webform_analysis_component_data_alter().
+ */
+function webform_localization_webform_analysis_component_data_alter(&$data, $node, &$component) {
+  // Gets webform localization options that match this node ID.
+  $wl_options = webform_localization_get_config($node->nid);
+  // Translate the translatable properties.
+  if ($wl_options['expose_strings']) {
+    module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
+    _webform_localization_translate_analysis_component($data, $component);
+  }
+}
+
 /**
  * Implements hook_form_FORM_ID_alter().
  *
  * Add specific localization options to Webform Configure Form
  */
 function webform_localization_form_webform_configure_form_alter(&$form, &$form_state, $form_id) {
+
   // Gets webform localization options that match this node ID.
   $webform_localization_options = webform_localization_get_config($form['nid']['#value']);
+
+  if ($webform_localization_options['expose_strings']) {
+    // Avoid caching for translatable element values.
+    entity_get_controller('node')->resetCache(array($form['nid']['#value']));
+    $form['#node'] = node_load($form['nid']['#value']);
+    $form['submission']['confirmation']['#default_value'] = $form['#node']->webform['confirmation'];
+    if ($form['submission']['redirection']['redirect']['#default_value'] == 'url') {
+      $form['submission']['redirection']['redirect_url']['#default_value'] = $form['#node']->webform['redirect_url'];
+    }
+    $form['advanced']['submit_text']['#default_value'] = $form['#node']->webform['submit_text'];
+  }
+
   $single_webform = 0;
   if ($webform_localization_options['single_webform'] > 0) {
     $single_webform = 1;
@@ -388,10 +433,16 @@ function webform_localization_form_webform_configure_form_alter(&$form, &$form_s
     '#description' => '<p>' . t('Keep the webform e-mail recipients synchronized in a translation set.') . '</p>',
   );
   $form['#submit'][] = '_webform_localization_webform_configure_form_submit';
+  if ($webform_localization_options['expose_strings']) {
+    // Using i18n string we need to tweak values before submit.
+    $submit_array = $form['#submit'];
+    array_unshift($submit_array, '_webform_localization_webform_configure_form_submit_i18n_tweaks');
+    $form['#submit'] = $submit_array;
+  }
 }
 
 /**
- * Handle specific localization options in Webform Configure Form
+ * Handle specific localization options in Webform Configure Form.
  */
 function _webform_localization_webform_configure_form_submit($form, &$form_state) {
 
@@ -439,6 +490,25 @@ function _webform_localization_webform_configure_form_submit($form, &$form_state
   }
 }
 
+/**
+ * Handle translated element tweaks in Webform Configure Form.
+ */
+function _webform_localization_webform_configure_form_submit_i18n_tweaks($form, &$form_state) {
+  global $language;
+  $default_language = language_default();
+  if ($default_language->language != $language->language) {
+    // Webform Configure Form not in default language.
+    module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
+    $name = webform_localization_i18n_string_name($form['#node']->webform['nid'], 'confirmation');
+    $string_source = i18n_string_get_string($name);
+    $string_translation = $form_state['values']['confirmation']['value'];
+    // We reset the source string value before saving the form.
+    $form_state['values']['confirmation']['value'] = $string_source->get_string();
+    // We save the translated string using i18n string.
+    i18n_string_translation_update($name, $string_translation, $language->language);
+  }
+}
+
 /**
  * Implements hook_form_FORM_ID_alter().
  *
@@ -578,9 +648,8 @@ function webform_localization_field_attach_prepare_translation_alter(&$entity, $
          * Perhaps could be interesting to copy only specific properties
          * but for now the entire webform make more sense.
          */
-          $entity->webform = $context['source_entity']->webform;
+        $entity->webform = $context['source_entity']->webform;
       }
-
     }
   }
 }
@@ -592,8 +661,9 @@ function webform_localization_field_attach_prepare_translation_alter(&$entity, $
  *   An array of webform localization options group by nid.
  * @param $nid
  *   A node Id.
- * @param boolean $clear_cache
+ * @param bool $clear_cache
  *   A flag to force a database reading in case that properties are cached.
+ *
  * @return array
  *   Webform localization options that match the nid.
  */
@@ -644,9 +714,10 @@ function webform_localization_get_config($nid, $clear_cache = FALSE) {
 
 /**
  * Global switch to enable / disable syncing.
+ *
  * This function also check whether we are synching at the moment.
  *
- * @return boolean
+ * @return bool
  *   TRUE if we need to run sync operations. FALSE during syncing
  *   so we don't have recursion.
  */
@@ -659,7 +730,7 @@ function _webform_localization_sync($status = NULL) {
 }
 
 /**
- * Translate webform confirmation field
+ * Translate webform confirmation field.
  */
 function webform_localization_preprocess_webform_confirmation(&$vars) {
   if (empty($vars['node']->tnid)) {
@@ -670,7 +741,7 @@ function webform_localization_preprocess_webform_confirmation(&$vars) {
   $query->innerJoin('webform_localization', 'wl', 'w.nid = wl.nid');
   $query->fields('w', array('nid'));
   $query->condition('wl.single_webform', $vars['node']->tnid, '=');
-  $query->condition('w.nid', $vars['node']->nid, '!=');
+  $query->condition('w.nid', $vars['node']->nid, '<>');
   $result = $query->execute()->fetchField();
   if ($result) {
     $source_node = node_load($result);
@@ -684,3 +755,44 @@ function webform_localization_preprocess_webform_confirmation(&$vars) {
   // Strip out empty tags added by WYSIWYG editors if needed.
   $vars['confirmation_message'] = drupal_strlen(trim(strip_tags($confirmation))) ? $confirmation : '';
 }
+
+/**
+ * Implements hook_form_webform_client_form_alter().
+ */
+function webform_localization_form_webform_client_form_alter(&$form, &$form_state, $form_id) {
+  if (!isset($form['#node']->webform['nid'])) {
+    return;
+  }
+  $webform_localization_options = webform_localization_get_config($form['#node']->webform['nid']);
+  if ($webform_localization_options['single_webform']) {
+    if (isset($form['details']['nid']['#value']) && $form['#node']->webform['nid'] == $form['#node']->tnid) {
+      // We keep current language node nid.
+      $form['details']['current_language_nid'] = array(
+        '#type' => 'value',
+        '#value' => $form['details']['nid']['#value'],
+      );
+      // Nid from the source webform for webform_validation.
+      $form['details']['nid']['#value'] = $form['#node']->webform['nid'];
+    }
+  }
+}
+
+/**
+ * Implements hook_modules_disabled().
+ */
+function webform_localization_modules_disabled($modules) {
+  if (in_array('uuid', $modules)) {
+    module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
+    webform_localization_uuid_update_strings(TRUE);
+  }
+}
+
+/**
+ * Implements hook_modules_enabled().
+ */
+function webform_localization_modules_enabled($modules) {
+  if (in_array('uuid', $modules)) {
+    module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
+    webform_localization_uuid_update_strings(FALSE);
+  }
+}

+ 41 - 28
sites/all/modules/contrib/form/webform_phone/webform_phone.components.inc

@@ -22,6 +22,7 @@ function _webform_defaults_phone() {
       'private'                    => FALSE,
       'attributes'                 => array(),
       'description'                => '',
+      'placeholder'                => '',
       'country'                    => 'ca',
       'phone_country_code'         => 0,
       'phone_default_country_code' => 1,
@@ -74,8 +75,8 @@ function _webform_edit_phone($component) {
     '#type'   => 'markup',
     '#value'  => t('International phone numbers are in the form +XX YYYYYYY where XX is a country code and YYYYYYY is the local number. This field type is based off of the <a href="http://www.itu.int/rec/T-REC-E.123/en">E.123 specification</a>.'),
     '#states' => array(
-      'visible' => array( // action to take.
-                          ':input[name="extra[country]"]' => array( 'value' => 'int' ),
+      'visible' => array(
+        ':input[name="extra[country]"]' => array( 'value' => 'int' ),
       ),
     ),
   );
@@ -84,8 +85,8 @@ function _webform_edit_phone($component) {
     '#title'         => t('Default country code to add to international numbers without one (omit + sign)'),
     '#default_value' => $component['extra']['phone_default_country_code'],
     '#states'        => array(
-      'visible' => array( // action to take.
-                          ':input[name="extra[country]"]' => array( 'value' => 'int' ),
+      'visible' => array(
+        ':input[name="extra[country]"]' => array( 'value' => 'int' ),
       ),
     ),
   );
@@ -94,8 +95,8 @@ function _webform_edit_phone($component) {
     '#title'         => t('Maximum length of international numbers, according to the ITU this is 15'),
     '#default_value' => $component['extra']['phone_int_max_length'],
     '#states'        => array(
-      'visible' => array( // action to take.
-                          ':input[name="extra[country]"]' => array( 'value' => 'int' ),
+      'visible' => array(
+        ':input[name="extra[country]"]' => array( 'value' => 'int' ),
       ),
     ),
   );
@@ -106,8 +107,8 @@ function _webform_edit_phone($component) {
     '#default_value' => $component['extra']['ca_phone_separator'],
     '#size'          => 2,
     '#states'        => array(
-      'visible' => array( // action to take.
-                          ':input[name="extra[country]"]' => array( 'value' => 'ca' ),
+      'visible' => array(
+        ':input[name="extra[country]"]' => array( 'value' => 'ca' ),
       ),
     ),
   );
@@ -116,8 +117,8 @@ function _webform_edit_phone($component) {
     '#title'         => t('Use parentheses around area code'),
     '#default_value' => $component['extra']['ca_phone_parentheses'],
     '#states'        => array(
-      'visible' => array( // action to take.
-                          ':input[name="extra[country]"]' => array( 'value' => 'ca' ),
+      'visible' => array(
+        ':input[name="extra[country]"]' => array( 'value' => 'ca' ),
       ),
     ),
   );
@@ -140,6 +141,14 @@ function _webform_edit_phone($component) {
     '#weight'        => 0,
     '#parents'       => array( 'extra', 'width' ),
   );
+  $form['display']['placeholder'] = array(
+    '#type'          => 'textfield',
+    '#title'         => t('Placeholder'),
+    '#default_value' => $component['extra']['placeholder'],
+    '#description'   => t('The text will be shown in the field until the user starts entering a value.'),
+    '#weight'        => 1,
+    '#parents'       => array( 'extra', 'placeholder' ),
+  );
   $form['display']['disabled'] = array(
     '#type'          => 'checkbox',
     '#title'         => t('Disabled'),
@@ -189,22 +198,26 @@ function _webform_render_phone($component, $value = NULL, $filter = TRUE) {
     '#weight'           => $component['weight'],
     '#translatable'     => array( 'title', 'description' ),
   );
-  if ( isset( $value ) ) {
+  if (isset( $value )) {
     $form_item['#default_value'] = $value[0];
   }
   // Change the 'width' option to the correct 'size' option.
-  if ( $component['extra']['width'] > 0 ) {
+  if ($component['extra']['width'] > 0) {
     $form_item['#size'] = $component['extra']['width'];
   }
-  if ( $component['extra']['disabled'] ) {
-    if ( $filter ) {
+  // Show the placeholder text if used.
+  if ($component['extra']['placeholder']) {
+    $form_item['#attributes']['placeholder'] = $component['extra']['placeholder'];
+  }
+  if ($component['extra']['disabled']) {
+    if ($filter) {
       $form_item['#attributes']['readonly'] = 'readonly';
     }
     else {
       $form_item['#disabled'] = TRUE;
     }
   }
-  if ( isset( $value[0] ) ) {
+  if (isset( $value[0] )) {
     $form_item['#default_value'] = $value[0];
   }
   return $form_item;
@@ -215,10 +228,10 @@ function _webform_render_phone($component, $value = NULL, $filter = TRUE) {
  */
 function webform_validate_phone($element, $form_state) {
   $value = $element['#value'];
-  if ( isset( $value ) && $value != '' ) {
+  if (isset( $value ) && $value != '') {
     $ccode = $element['#webform_component']['extra']['country'];
     //run through 'phone' module's validation
-    if ( !valid_phone_number($ccode, $value) ) {
+    if (!valid_phone_number($ccode, $value)) {
       $country = phone_country_info($ccode);
       form_error($element, t($country['error'], array( '%value' => $value )));
     }
@@ -272,7 +285,7 @@ function _webform_display_phone($component, $value, $format = 'html') {
 function theme_webform_display_phonefield($variables) {
   $element = $variables['element'];
   $plain_value = check_plain($element['#value']);
-  if ( $element['#format'] == 'html' ) {
+  if ($element['#format'] == 'html') {
     //Use smarter detection if available for formatting the output
     $is_mobile_device = module_exists('mobile_tools') ? mobile_tools_is_mobile_device() : strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== FALSE;
     $value = ( $is_mobile_device ) ? '<a href="tel:' . $plain_value . '">' . $plain_value . '</a>' : $plain_value;
@@ -304,8 +317,8 @@ function theme_webform_display_phonefield($variables) {
  */
 function _webform_submit_phone($component, $value) {
   $ccode = $component['extra']['country'];
-  if ( phone_countries($ccode) !== NULL ) {
-    if ( isset( $value ) && !empty( $value ) ) {
+  if (phone_countries($ccode) !== NULL) {
+    if (isset( $value ) && !empty( $value )) {
       //Use 'phone' module to format the number
       return format_phone_number($ccode, $value, $component['extra']);
     }
@@ -336,14 +349,14 @@ function _webform_submit_phone($component, $value) {
 function _webform_analysis_phone($component, $sids = array(), $single = FALSE) {
   // Generate the list of options and questions.
   $query = db_select('webform_submitted_data', 'wsd', array( 'fetch' => PDO::FETCH_ASSOC ))->fields('wsd', array( 'data' ))->condition('nid', $component['nid'])->condition('cid', $component['cid']);
-  if ( count($sids) ) {
+  if (count($sids)) {
     $query->condition('sid', $sids, 'IN');
   }
   $non_blanks = 0;
   $submissions = 0;
   $result = $query->execute();
-  foreach ( $result as $data ) {
-    if ( drupal_strlen(trim($data['data'])) > 0 ) {
+  foreach ($result as $data) {
+    if (drupal_strlen(trim($data['data'])) > 0) {
       $non_blanks++;
     }
     $submissions++;
@@ -422,11 +435,11 @@ function _webform_csv_data_phone($component, $export_options, $value) {
 }
 
 /**
- The first hook provides the name and position of the field in the Form Builder palette, as well as a default element to display when the field is pulled out of the palette.
-The second hook maps the component properties and options to FormAPI properties that Form Builder can manipulate.
-Form Builder then will manage pulling the form out of the normal Webform configuration form, loading configuration, and saving it.
-There are plenty of examples in the form_builder_webform.components.inc file that other modules (such as Webform Phone Number) can use as templates.
-I'm moving this request over to that module's queue, and changing to a feature request.
+ * The first hook provides the name and position of the field in the Form Builder palette, as well as a default element to display when the field is pulled out of the palette.
+ * The second hook maps the component properties and options to FormAPI properties that Form Builder can manipulate.
+ * Form Builder then will manage pulling the form out of the normal Webform configuration form, loading configuration, and saving it.
+ * There are plenty of examples in the form_builder_webform.components.inc file that other modules (such as Webform Phone Number) can use as templates.
+ * I'm moving this request over to that module's queue, and changing to a feature request.
  */
 /**
  * @defgroup form-builder-webform-phone-callbacks Callbacks for the Phone component

+ 5 - 4
sites/all/modules/contrib/form/webform_phone/webform_phone.info

@@ -2,12 +2,13 @@ name = Webform Phone Number
 description = "Phone Field type for webform."
 package = "Webform"
 dependencies[] = webform
-dependencies[] = phone
+dependencies[] = phone (1.x)
 files[] = webform_phone.module
 core = 7.x
-; Information added by Drupal.org packaging script on 2014-10-16
-version = "7.x-1.19"
+
+; Information added by Drupal.org packaging script on 2015-01-06
+version = "7.x-1.21"
 core = "7.x"
 project = "webform_phone"
-datestamp = "1413479630"
+datestamp = "1420529914"
 

+ 2 - 2
sites/all/modules/contrib/mail/webform_simplenews/webform_simplenews.info

@@ -6,9 +6,9 @@ dependencies[] = webform
 dependencies[] = simplenews
 files[] = webform_simplenews.inc
 
-; Information added by drupal.org packaging script on 2013-10-01
+; Information added by drupal.org packaging script on 2013-10-26
 version = "7.x-1.x-dev"
 core = "7.x"
 project = "webform_simplenews"
-datestamp = "1380659452"
+datestamp = "1382756138"