Returns the default language code assigned to an entity type and a bundle.
string $entity_type: The entity type.
string $bundle: The bundle name.
string The language code.
function language_get_default_langcode($entity_type, $bundle) {
$configuration = language_get_default_configuration($entity_type, $bundle);
if (!isset($configuration['langcode'])) {
$configuration['langcode'] = 'site_default';
}
$default_value = NULL;
$language_interface = language(Language::TYPE_INTERFACE);
switch ($configuration['langcode']) {
case 'site_default':
$default_value = language_default()->langcode;
break;
case 'current_interface':
$default_value = $language_interface->langcode;
break;
case 'authors_default':
global $user;
if (!empty($user->preferred_langcode)) {
$default_value = $user->preferred_langcode;
}
else {
$default_value = $language_interface->langcode;
}
break;
}
if ($default_value) {
return $default_value;
}
// If we still do not have a default value, just return the value stored in
// the configuration; it has to be an actual language code.
return $configuration['langcode'];
}