You are here

function webform_localization_component_get_translations in Webform Localization 7.4

Same name and namespace in other branches
  1. 7 includes/webform_localization.component.sync.inc \webform_localization_component_get_translations()

Get an array with translated versions of a component.

This array is later used to run sync operations on components.

@staticvar array $component_translations An array of webform components for each tnid.

Parameters

array $component: A webform component array.

Return value

array An array of webform components that match a tnid.

1 call to webform_localization_component_get_translations()
webform_localization_webform_component_presave in ./webform_localization.module
Implements hook_webform_component_presave().

File

includes/webform_localization.component.sync.inc, line 28
Webform Localization Component Sync Functions.

Code

function webform_localization_component_get_translations($component) {
  static $component_translations = array();
  $node = node_load($component['nid']);
  $translations = translation_node_get_translations($node->tnid);
  $component_translations[$node->tnid] = array();
  if (!empty($translations) && !isset($component_translations[$node->tnid])) {
    $nid_list = array();
    foreach ($translations as $trans_node) {
      $nid_list[] = $trans_node->nid;
    }

    // Load components for each translated node.
    if (!empty($nid_list)) {
      $components = db_select('webform_component')
        ->fields('webform_component')
        ->condition('nid', $nid_list, 'IN')
        ->condition('cid', $component['cid'], '=')
        ->orderBy('nid')
        ->execute()
        ->fetchAllAssoc('nid', PDO::FETCH_ASSOC);

      // Cleanup on each component.
      foreach ($components as $cid => $c) {
        $components[$cid]['nid'] = $c['nid'];
        $components[$cid]['extra'] = unserialize($c['extra']);
        webform_component_defaults($components[$cid]);
      }
      $component_translations[$node->tnid] = $components;
    }
  }
  return $component_translations[$node->tnid];
}