function language_get_default_langcode in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/language.module \language_get_default_langcode()
Returns the default language code assigned to an entity type and a bundle.
Parameters
string $entity_type: The entity type.
string $bundle: The bundle name.
Return value
string The language code.
4 calls to language_get_default_langcode()
- DefaultLanguageItem::getDefaultLangcode in core/
modules/ language/ src/ DefaultLanguageItem.php - Provides default language code of given entity.
- LanguageConfigurationElementTest::buildForm in core/
modules/ language/ tests/ language_elements_test/ src/ Form/ LanguageConfigurationElementTest.php - Form constructor.
- LanguageConfigurationElementTest::testDefaultLangcode in core/
modules/ language/ src/ Tests/ LanguageConfigurationElementTest.php - Tests that the language_get_default_langcode() returns the correct values.
- NodeFieldMultilingualTest::testMultilingualNodeForm in core/
modules/ node/ src/ Tests/ NodeFieldMultilingualTest.php - Tests whether field languages are correctly set through the node form.
File
- core/
modules/ language/ language.module, line 236 - Add language handling functionality to Drupal.
Code
function language_get_default_langcode($entity_type, $bundle) {
$configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle);
$default_value = NULL;
$language_interface = \Drupal::languageManager()
->getCurrentLanguage();
switch ($configuration
->getDefaultLangcode()) {
case LanguageInterface::LANGCODE_SITE_DEFAULT:
$default_value = \Drupal::languageManager()
->getDefaultLanguage()
->getId();
break;
case 'current_interface':
$default_value = $language_interface
->getId();
break;
case 'authors_default':
$user = \Drupal::currentUser();
$language_code = $user
->getPreferredLangcode();
if (!empty($language_code)) {
$default_value = $language_code;
}
else {
$default_value = $language_interface
->getId();
}
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
->getDefaultLangcode();
}