array( 'name' => t('String Overides'), 'default_hook' => 'stringoverrides_features_defaults', 'features_source' => TRUE, 'file' => drupal_get_path('module', 'stringoverrides') . '/stringoverrides.features.inc', ), ); } /** * Features callback; Retrieves the String Overrides defaults. */ function stringoverrides_features_defaults() { return array(); } /** * Implements hook_features_export(). */ function stringoverrides_features_export($data, &$export, $module_name) { foreach ($data as $name => $value) { // Split the unique component name into the language, context and override. list($lang, $context, $original) = explode(':', $name, 3); // Retrieve the value of the override within its context. $overrides = variable_get('locale_custom_strings_' . $lang, array()); $override = $overrides[$context][$original]; // Set up the exportable component value. $export['features']['stringoverrides'][$name] = $name; $export['dependencies']['stringoverrides'] = 'stringoverrides'; } return array(); } /** * Implements hook_features_export_options(). */ function stringoverrides_features_export_options() { $options = array(); // Retrieve all the enabled overrides for each given language. $result = db_select('variable', 'v') ->fields('v') ->condition('name', 'locale_custom_strings_%', 'LIKE') ->execute(); // Go through all of the variables. foreach ($result as $variable) { // Retrieve each override set. $overrideset = variable_get($variable->name, array()); $lang = str_replace('locale_custom_strings_', '', $variable->name); // Each override set first has the context. foreach ($overrideset as $context => $overrides) { // Each context contains all the overrides. foreach ($overrides as $original => $replacement) { // Constuct the unique name for the override. $name = $lang . ':' . $context . ':' . $original; $options[$name] = t('!lang: !original', array( '!lang' => $lang, '!original' => $original, )); } } } return $options; } /** * Implements hook_features_export_render(). */ function stringoverrides_features_export_render($module_name, $data, $export = NULL) { $output = array(); $code = ''; foreach ($data as $index => $name) { // Split the unique component name into the language, context and override. list($lang, $context, $original) = explode(':', $name, 3); // Retrieve the value of the override within its context. $overrides = variable_get('locale_custom_strings_' . $lang, array()); // Add the value of the override directly to the output. $replacement = $overrides[$context][$original]; $code .= ' $stringoverrides[' . features_var_export($name) . '] = ' . features_var_export($replacement) . ";\n"; } // Constuct the output code. $code .= ' return $stringoverrides;'; return array('stringoverrides_defaults' => $code); } /** * Implements hook_features_export_revert(). */ function stringoverrides_features_export_revert($module_name) { $stringoverrides = module_invoke_all($module_name, 'stringoverrides_defaults'); if (!empty($stringoverrides)) { foreach ($stringoverrides as $name => $value) { // Split the unique component name into the language, context and override. list($lang, $context, $override) = explode(':', $name, 3); // Retrieve the value of the override within its context. $overrides = variable_get('locale_custom_strings_' . $lang, array()); // Delete the override. unset($overrides[$context][$override]); variable_set('locale_custom_strings_' . $lang, $overrides); } } } /** * Implements hook_features_export_rebuild(). */ function stringoverrides_features_export_rebuild($module_name) { $stringoverrides = module_invoke_all($module_name, 'stringoverrides_defaults'); if (!empty($stringoverrides)) { foreach ($stringoverrides as $name => $value) { // Split the unique component name into the language, context and override. list($lang, $context, $override) = explode(':', $name, 3); $overrides = variable_get('locale_custom_strings_' . $lang, array()); $overrides[$context][$override] = $value; variable_set('locale_custom_strings_' . $lang, $overrides); } } }