You are here

function webform_localization_webform_component_presave in Webform Localization 7.4

Same name and namespace in other branches
  1. 7 webform_localization.module \webform_localization_webform_component_presave()

Implements hook_webform_component_presave().

File

./webform_localization.module, line 194
Webform localization module.

Code

function webform_localization_webform_component_presave(&$component) {

  // If this is an insert, skip handling as this is handled by
  // hook_webform_component_insert().
  if (empty($component['cid'])) {
    return;
  }

  // Gets webform localization options that match this node ID.
  $wl_options = webform_localization_get_config($component['nid']);

  // Create translation source for i18n_string for all the translatable
  // properties.
  if ($wl_options['expose_strings']) {
    module_load_include('inc', 'webform_localization', 'includes/webform_localization.i18n');
    webform_localization_component_update_translation_strings($component);
  }
  if ($wl_options['sync_components'] && _webform_localization_sync()) {
    if (!module_exists('translation')) {

      // Enable the translation module as it is needed for localization sync.
      module_enable('translation');
    }
    $test_node = node_load($component['nid']);
    if ($test_node->tnid > 0) {

      // Turn Off Sync.
      _webform_localization_sync(FALSE);
      module_load_include('inc', 'webform_localization', 'includes/webform_localization.component.sync');

      // Get all versions of the component across all translations.
      $translations = webform_localization_component_get_translations($component);
      unset($translations[$component['nid']]);

      // Sync the changed component with it's translations versions.
      webform_localization_component_sync($component, $translations);
      foreach ($translations as $trans_c) {
        webform_component_update($trans_c);
      }

      // Turn On Sync.
      _webform_localization_sync(TRUE);
    }
    else {
      debug('configuration error: webform_localization_sync enabled AND Keep a single webform across a translation set. but no tnid, to resolve this either disable <Keep a single webform across a translation set> by unchecking this option, or enable node translation on the webform', t('debug'));
    }
  }
}