You are here

function webform_localization_preprocess_webform_components_form in Webform Localization 7.4

Implements hook_preprocess_webform_components_form().

Adds a translate link to each webform component.

File

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

Code

function webform_localization_preprocess_webform_components_form(&$variables) {
  $form = $variables['form'];
  if (!isset($form['#node']->webform['nid'])) {
    return;
  }
  $header = $variables['header'];
  $rows = $variables['rows'];
  $node = $form['#node'];
  $enabled_languages = locale_language_list('name');
  $webform_localization_options = webform_localization_get_config($form['#node']->webform['nid']);
  $row_data = array();
  if ($webform_localization_options['expose_strings'] && count($enabled_languages) > 1) {

    // Change colspan of header and footer.
    $footer = array_pop($rows);
    $header[6]['colspan'] = 4;
    $footer['data'][6]['colspan'] = 4;

    // Add translate link to rows.
    foreach ($rows as $key => $row) {
      $row_data[$key] = $row;
      if (isset($row['data-cid'])) {
        $name = webform_localization_i18n_string_name($node->nid, $row['data-cid'], '#title');
        $string_source = i18n_string_get_string($name);
        if (isset($string_source->lid) && !empty($string_source->lid)) {
          $row_data[$key]['data'][] = l(t('Translate'), 'admin/config/regional/translate/edit/' . $string_source->lid, array(
            'query' => drupal_get_destination(),
          ));
        }
        else {

          // Markup components do not have a translatable title, look for markup instead
          $name = webform_localization_i18n_string_name($node->nid, $row['data-cid'], '#markup');
          $string_source = i18n_string_get_string($name);
          if (isset($string_source->lid) && !empty($string_source->lid)) {
            $row_data[$key]['data'][] = l(t('Translate'), 'admin/config/regional/translate/edit/' . $string_source->lid, array(
              'query' => drupal_get_destination(),
            ));
          }
          else {

            // this component does not have anything translatable, so don't show a link
            $row_data[$key]['data'][] = '';
          }
        }
      }
    }
    $variables['rows'] = $row_data;
    $variables['rows'][] = $footer;
    $variables['header'] = $header;
    $variables['form'] = $form;
  }
}