function _field_language_suggestion

7.x field.multilingual.inc _field_language_suggestion($available_languages, $language_suggestion, $field_name)

Process the given language suggestion based on the available languages.

If a non-empty language suggestion is provided it must appear among the available languages, otherwise it will be ignored.

Parameters

$available_languages: An array of valid language codes.

$language_suggestion: A language code or an array of language codes keyed by field name.

$field_name: The name of the field being processed.

Return value

An array of valid language codes.

Related topics

2 calls to _field_language_suggestion()
_field_invoke in drupal-7.x/modules/field/field.attach.inc
Invoke a field hook.
_field_invoke_multiple in drupal-7.x/modules/field/field.attach.inc
Invoke a field hook across fields on multiple entities.

File

drupal-7.x/modules/field/field.multilingual.inc, line 131
Functions implementing Field API multilingual support.

Code

function _field_language_suggestion($available_languages, $language_suggestion, $field_name) {
  // Handle possible language suggestions.
  if (!empty($language_suggestion)) {
    // We might have an array of language suggestions keyed by field name.
    if (is_array($language_suggestion) && isset($language_suggestion[$field_name])) {
      $language_suggestion = $language_suggestion[$field_name];
    }

    // If we have a language suggestion and the suggested language is available,
    // we return only it.
    if (in_array($language_suggestion, $available_languages)) {
      $available_languages = array($language_suggestion);
    }
  }

  return $available_languages;
}