function 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.

6 calls to language_get_default_langcode()
EntityNormalizer::denormalize in drupal/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize().
LanguageConfigurationElementTest::testDefaultLangcode in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php
Tests that the language_get_default_langcode() returns the correct values.
language_elements_configuration_element_test in drupal/core/modules/language/tests/language_elements_test/language_elements_test.module
A form containing a language select element.
NodeFieldMultilingualTestCase::testMultilingualDisplaySettings in drupal/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php
NodeFieldMultilingualTestCase::testMultilingualNodeForm in drupal/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php
Tests whether field languages are correctly set through the node form.

... See full list

File

drupal/core/modules/language/language.module, line 433
Add language handling functionality to Drupal.

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'];
}