You are here

function i18nprofile_profile_alter in Internationalization 5

Same name and namespace in other branches
  1. 5.3 i18nprofile/i18nprofile.module \i18nprofile_profile_alter()
  2. 5.2 i18nprofile/i18nprofile.module \i18nprofile_profile_alter()
  3. 6 i18nprofile/i18nprofile.module \i18nprofile_profile_alter()

Implementation of hook_profile_alter()

File

i18nprofile/i18nprofile.module, line 62

Code

function i18nprofile_profile_alter($account, &$fields) {

  // var_dump($fields['Personal information']);
  // Remove translated categories
  $categories = i18nprofile_categories(TRUE);
  foreach ($categories as $category => $translation) {

    // Translate field titles and names
    $i18nfields = i18nprofile_fields($category);
    foreach ($i18nfields as $name => $field) {
      if (isset($fields[$category][$name])) {
        if ($field->title) {
          $fields[$category][$name]['title'] = $field->title;
        }
        if ($field->type == 'selection' && ($options = unserialize($field->options))) {
          $value = $fields[$category][$name]['value'];
          $fields[$category][$name]['value'] = isset($options[$value]) ? $options[$value] : $value;
        }
      }
    }
    if ($translation && $category != $translation) {
      $fields[$translation] = $fields[$category];
      unset($fields[$category]);
    }
  }
}