You are here

function node_import_check_language in Node import 6

Check if the supplied value for the language field is a valid language.

1 string reference to 'node_import_check_language'
locale_node_import_fields_alter in supported/locale.inc
Implementation of hook_node_import_fields_alter().

File

supported/locale.inc, line 42
Support file for core locale module.

Code

function node_import_check_language(&$value, $field, $options, $preview) {
  $lvalue = drupal_strtolower($value);
  foreach (language_list() as $code => $data) {

    // allow use of language code
    if ($lvalue == '' || $lvalue == drupal_strtolower($code)) {
      $value = $code;
      return TRUE;
    }

    // allow use of english or native language name
    if ($lvalue == drupal_strtolower($data->name) || $lvalue == drupal_strtolower($data->native)) {
      $value = $code;
      return TRUE;
    }

    // allow use of language name translated into current language
    if ($lvalue == drupal_strtolower(t($data->name))) {
      $value = $code;
      return TRUE;
    }
  }
  node_import_input_error(t('Input error: %value is not allowed for %name (not a language).', array(
    '%value' => $value,
    '%name' => $field['title'],
  )));
  return FALSE;
}