- <?php
- * @file
- * Install, update and uninstall functions for the language module.
- */
-
- * Implements hook_install().
- */
- function language_install() {
-
- language_save(language_default());
- }
-
- * Implements hook_uninstall().
- */
- function language_uninstall() {
-
- $config = config('system.core');
- $config->set('language_default', 'en');
- $config->set('language_count', 1);
- $config->save();
-
-
-
- backdrop_static_reset('language_default');
- backdrop_language_initialize();
- }
-
- * Implements hook_schema().
- */
- function language_schema() {
- $schema['language'] = array(
- 'description' => 'List of all available languages in the system.',
- 'fields' => array(
- 'langcode' => array(
- 'type' => 'varchar',
- 'length' => 12,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "Language code, e.g. 'de' or 'en-US'.",
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 64,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Language name.',
- ),
- 'direction' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).',
- ),
- 'enabled' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Enabled flag (1 = Enabled, 0 = Disabled).',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Weight, used in lists of languages.',
- ),
- ),
- 'primary key' => array('langcode'),
- 'indexes' => array(
- 'list' => array('weight', 'name'),
- ),
- );
- return $schema;
- }
-
- * @addtogroup updates-7.x-to-1.x
- * @{
- */
-
- * Rename {language}.language to {language}.langcode.
- *
- * @see update_prepare_language()
- */
- function language_update_1000() {
-
- if (db_field_exists('language', 'language')) {
- db_drop_primary_key('language');
- $langcode_spec = array(
- 'type' => 'varchar',
- 'length' => 12,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => "Language code, e.g. 'de' or 'en-US'.",
- );
- db_change_field('language', 'language', 'langcode', $langcode_spec, array('primary key' => array('langcode')));
- }
-
-
- $language_default = update_variable_get('language_default');
- if (!empty($language_default) && isset($language_default->language)) {
- $language_default->langcode = $language_default->language;
- unset($language_default->language);
- update_variable_set('language_default', $language_default);
- }
- }
-
- * Convert language settings to config.
- */
- function language_update_1001() {
-
- $default_language = update_variable_get('language_default', (object) array(
- 'langcode' => 'en',
- 'name' => 'English',
- 'direction' => 0,
- 'enabled' => TRUE,
- 'weight' => 0,
- ));
- $core_config = config('system.core');
-
-
- $core_config->set('language_default', $default_language->langcode);
- $core_config->set('language_count', update_variable_get('language_count'));
- $core_config->save();
-
-
- $language_config = config('language.settings');
- $language_config->set('_config_static', TRUE);
-
-
-
- $negotiation = array(
- 'language_content' => array(),
- 'language' => array(),
- 'language_url' => array(),
- );
- foreach ($negotiation as $language_type => $negotiation_data) {
- $negotiation_data = update_variable_get('language_negotiation_' . $language_type, array());
- $negotiation[$language_type] = array_keys($negotiation_data);
- }
- array_filter($negotiation);
- $language_config->set('language_negotiation', $negotiation);
-
- $language_config->save();
-
-
- update_variable_del('language_default');
- update_variable_del('language_count');
- update_variable_del('language_negotiation_language_content');
- update_variable_del('language_negotiation_language');
- update_variable_del('language_negotiation_language_url');
-
-
- update_variable_del('language_types');
- }
-
- * Convert the language database table to config.
- */
- function language_update_1002() {
- if (db_table_exists('language')) {
- $languages = db_query("SELECT * FROM {language}")->fetchAllAssoc('langcode');
- $config = config('language.settings');
- $config->set('_config_static', TRUE);
- $config->set('languages', $languages);
- $config->save();
-
- db_drop_table('language');
- }
- }
-
- * Add the native name to all enabled languages.
- */
- function language_update_1003() {
- require_once BACKDROP_ROOT . '/core/includes/standard.inc';
- $predefined = standard_language_list();
- $config = config('language.settings');
- $languages = $config->get('languages');
-
- foreach ($languages as $langcode => $lang) {
- if (!empty($lang['native'])) {
- continue;
- }
- if (isset($predefined[$langcode][1])) {
- $config->set('languages.' . $langcode . '.native', $predefined[$langcode][1]);
- }
- else {
- $config->set('languages.' . $langcode . '.native', $lang['name']);
- }
- }
- $config->save();
- }
-
- * @} End of "addtogroup updates-7.x-to-1.x"
- * The next series of updates should start at 2000.
- */