Last active
December 16, 2015 14:40
-
-
Save vijaycs85/5450727 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
<?php | |
/** | |
* 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']; | |
// For the form submission handling, use the override free context. | |
config_context_enter('config.context.free'); | |
// $existing_translation_objects = locale_storage()->getTranslations(array('language' => $language->langcode, 'translated' => TRUE)); | |
foreach ($group->getNames() as $id => $name) { | |
// Set config values based on form submission and original values. | |
$base_config = config($name); | |
$translation_config = config('locale.config.' . $language->langcode . '.' . $name); | |
config_translation_set_config($base_config, $translation_config, $form_values[$id]); | |
// If no overrides, delete language specific config file. | |
$saved_config = $translation_config->get(); | |
if (empty($saved_config)) { | |
$translation_config->delete(); | |
} | |
else { | |
$translation_config->save(); | |
$locations = locale_storage()->getLocations(array('type' => 'configuration', 'name' => $name)); | |
if (!empty($locations)) { | |
// This was a shipped config file so save translations with locale DB too. | |
$target = locale_storage()->createTranslation(array('lid' => $locations->lid, 'language' => $language->langcode));print_r($target);exit; | |
$target->save($saved_config); | |
} | |
} | |
} | |
config_context_leave(); | |
drupal_set_message(t('Updated @language configuration translations successfully.', array('@language' => $language->name))); | |
$form_state['redirect'] = $group->getBasePath() . '/translate'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment