Last active
December 15, 2015 10:39
-
-
Save vijaycs85/5247798 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Submit handler to save config translation. | |
*/ | |
function config_translation_form_submit(&$form, &$form_state) { | |
$form_values = $form_state['values']; | |
$language = $form_values['language']; | |
$group = $form_values['group']; | |
foreach ($group->getNames() as $id => $name) { | |
$config = config('locale.config.' . $language->langcode . '.' . $name); | |
$base_config = config_translation_get_base_config($name); | |
// Pass base configuration to check and save only overrides. | |
config_translation_set_config($base_config, $config, $form_values[$id]); | |
$saved_config = $config->get(); | |
// If no overrides, delete locale file. | |
if (empty($saved_config)) { | |
$config->delete(); | |
} else { | |
$config->save(); | |
} | |
} | |
drupal_set_message(t('Updated @language configuration translations successfully.', array('@language' => $language->name))); | |
$form_state['redirect'] = $group->getBasePath() . '/translate'; | |
} | |
function config_translation_get_base_config($name) { | |
config_context_enter('config.context.free'); | |
$base_config = config($name)->get(); | |
config_context_leave(); | |
return $base_config; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment