function field_valid_language in Drupal 7
Ensures that a given language code is valid.
Checks whether the given language is one of the enabled languages. Otherwise, it returns the current, global language; or the site's default language, if the additional parameter $default is TRUE.
Parameters
$langcode: The language code to validate.
$default: Whether to return the default language code or the current language code in case $langcode is invalid.
Return value
A valid language code.
Related topics
3 calls to field_valid_language()
- FieldTranslationsTestCase::testFieldFormTranslationRevisions in modules/
field/ tests/ field.test - Tests field translations when creating a new revision.
- field_attach_form in modules/
field/ field.attach.inc - Add form elements for all fields for an entity to a form structure.
- field_language in modules/
field/ field.multilingual.inc - Returns the display language for the fields attached to the given entity.
File
- modules/
field/ field.multilingual.inc, line 228 - Functions implementing Field API multilingual support.
Code
function field_valid_language($langcode, $default = TRUE) {
$enabled_languages = field_content_languages();
if (in_array($langcode, $enabled_languages)) {
return $langcode;
}
global $language_content;
return $default ? language_default('language') : $language_content->language;
}