function language_save

API function to add or update a language.

Parameters

$language: Language object with properties corresponding to 'language' table columns.

44 calls to language_save()
BlockLanguageCacheTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/BlockLanguageCacheTest.php
Sets up a Drupal site for running functional and integration tests.
CacheDecoratorLanguageTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php
Sets up a Drupal site for running functional and integration tests.
ConfigLocaleOverride::testConfigLocaleUserAndGlobalOverride in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php
Tests locale override in combination with global overrides.
ConfigLocaleOverride::testConfigLocaleUserOverride in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php
Tests locale override based on user's preferred language.
EntityAccessTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php
Sets up Drupal unit test environment.

... See full list

File

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

Code

function language_save($language) {
  $language->is_new = !(bool) db_query_range('SELECT 1 FROM {language} WHERE langcode = :langcode', 0, 1, array(
    ':langcode' => $language->langcode,
  ))
    ->fetchField();

  // Let other modules modify $language before saved.
  module_invoke_all('language_presave', $language);

  // Save the record and inform others about the change.
  $t_args = array(
    '%language' => $language->name,
    '%langcode' => $language->langcode,
  );
  if ($language->is_new) {
    drupal_write_record('language', $language);
    module_invoke_all('language_insert', $language);
    watchdog('language', 'The %language (%langcode) language has been created.', $t_args);
  }
  else {
    drupal_write_record('language', $language, array(
      'langcode',
    ));
    module_invoke_all('language_update', $language);
    watchdog('language', 'The %language (%langcode) language has been updated.', $t_args);
  }
  if (!empty($language->default)) {

    // Set the new version of this language as default in a variable.
    variable_set('language_default', (array) $language);
  }

  // Update language count based on unlocked language count.
  language_update_count();

  // Update weight of locked system languages.
  language_update_locked_weights();

  // Kill the static cache in language_list().
  drupal_static_reset('language_list');
  language_negotiation_include();

  // Update URL Prefixes for all languages after the new default language is
  // propagated and the language_list() cache is flushed.
  language_negotiation_url_prefixes_update();
  return $language;
}