Created
January 30, 2014 14:07
-
-
Save DuaelFr/8709046 to your computer and use it in GitHub Desktop.
Enable default language during drupal profile installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Install, update and uninstall functions for the myprofile installation profile. | |
*/ | |
/** | |
* Implements hook_install(). | |
* | |
* Performs actions to set up the site for this profile. | |
* | |
* @see system_install() | |
*/ | |
function myprofile_install() { | |
// Allow visitors to register. | |
variable_set('user_register', USER_REGISTER_VISITORS); | |
// Give access to the published content to everyone. | |
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content')); | |
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content')); | |
} | |
/** | |
* Implements hook_install_tasks(). | |
*/ | |
function myprofile_install_tasks(&$install_state) { | |
$tasks = array(); | |
$tasks['myprofile_install_theme'] = array( | |
'display_name' => st('myprofile install theme'), | |
'display' => TRUE, | |
'type' => 'normal', | |
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED, | |
'function' => '_myprofile_install_theme', | |
); | |
$tasks['myprofile_install_locale'] = array( | |
'display_name' => st('myprofile install locale'), | |
'display' => TRUE, | |
'type' => 'batch', | |
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED, | |
'function' => '_myprofile_install_locale', | |
); | |
return $tasks; | |
} | |
/** | |
* Install task callback. | |
*/ | |
function _myprofile_install_theme() { | |
// Use the same name as the profile for the default theme. | |
$theme_name = basename(__DIR__); | |
// Set default theme. | |
theme_enable(array($theme_name)); | |
theme_disable(array('bartik', 'garland', 'seven', 'stark')); | |
variable_set('theme_default', $theme_name); | |
variable_set('admin_theme', 'rubik'); | |
variable_set('node_admin_theme', FALSE); | |
// Disable all blocks by default except system-main. Use context to enable them. | |
db_update('block') | |
->fields(array('region' => -1)) | |
->condition( | |
db_or() | |
->condition('delta', 'main', '!=') | |
->condition('module', 'system', '!=') | |
) | |
->execute(); | |
} | |
/** | |
* Install task callback. | |
*/ | |
function _myprofile_install_locale(&$install_state) { | |
include_once DRUPAL_ROOT . '/includes/locale.inc'; | |
$install_locale = $install_state['parameters']['locale']; | |
$enabled_langs = locale_language_list(); | |
// Disable previously default English language. | |
if (array_key_exists('en', $enabled_langs)) { | |
db_update('languages') | |
->fields(array( | |
'enabled' => '0', | |
)) | |
->condition('language', 'en') | |
->execute(); | |
} | |
// Enable language FR on if no language has been selected. | |
if ($install_locale == 'en' && !array_key_exists('fr', $enabled_langs)) { | |
locale_add_language('fr', 'French', 'Français', LANGUAGE_LTR, '', 'fr', TRUE, TRUE); | |
} | |
// Build batch with l10n_update module. | |
// Second pass will only update translations of freshly installed modules. | |
// We force each step to refresh its cache, as modules may have been | |
// installed since last call. | |
$history = l10n_update_get_history(TRUE); | |
module_load_include('check.inc', 'l10n_update'); | |
// This variable forces l10n_update to rebuild its projects list. | |
variable_set('l10n_update_rebuild_projects', 1); | |
$available = l10n_update_available_releases(TRUE); | |
$updates = l10n_update_build_updates($history, $available); | |
module_load_include('batch.inc', 'l10n_update'); | |
$updates = _l10n_update_prepare_updates($updates, NULL, array()); | |
// Overwrite previous translations, as the downloaded ones are the most | |
// recent, and valid. | |
$batch = l10n_update_batch_multiple($updates, LOCALE_IMPORT_OVERWRITE); | |
return $batch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment