View source
<?php
function spaces_customtext_settings_form($form, $form_state, $feature) {
global $language;
$langcode = $language->language;
$custom_strings = variable_get("locale_custom_strings_{$langcode}", array());
$strings = spaces_customtext_feature_strings($feature);
if (!empty($strings)) {
foreach ($strings as $original) {
$form[$original] = array(
'#type' => 'textfield',
'#title' => check_plain($original),
'#default_value' => isset($custom_strings[$original]) ? $custom_strings[$original] : '',
);
}
$master["locale_custom_strings_{$langcode}"] = $form;
$master["locale_custom_strings_{$langcode}"]['#tree'] = TRUE;
$master["locale_custom_strings_{$langcode}"]['#theme'] = 'spaces_customtext_settings_form';
$master["locale_custom_strings_{$langcode}"]['#element_validate'] = array(
'spaces_customtext_settings_validate',
);
$master["locale_custom_strings_{$langcode}"]['#custom_strings'] = $custom_strings;
$master = system_settings_form($master);
return $master;
}
drupal_not_found();
exit;
}
function spaces_customtext_settings_validate(&$element, &$form_state) {
$name = end($element['#parents']);
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Reset to defaults')) {
$form_state['values'][$name] = array_diff_key($element['#custom_strings'], $form_state['values'][$name]);
$form_state['values']['op'] = t('Save configuration');
}
else {
$form_state['values'][$name] = array_merge($element['#custom_strings'], $form_state['values'][$name]);
$form_state['values'][$name] = array_filter($form_state['values'][$name], 'trim');
}
}
function theme_spaces_customtext_settings_form() {
drupal_add_css(drupal_get_path('module', 'spaces_customtext') . '/spaces_customtext.css');
$rows = array();
foreach (element_children($element) as $key) {
$label = $element[$key]['#title'];
unset($element[$key]['#title']);
$rows[] = array(
$label,
drupal_render($element[$key]),
);
}
$output = theme('table', array(
'header' => array(
t('Original'),
t('Customized'),
),
'rows' => $rows,
'attributes' => array(
'class' => 'spaces-customtext',
),
));
$output .= drupal_render($element);
return $output;
}
function spaces_customtext_feature_strings($feature) {
global $language;
$langcode = $language->language;
$features = spaces_features(spaces_get_space() ? spaces_get_space()->type : 'site');
$strings = array();
if (isset($features[$feature])) {
$language->language = 'spaces_customtext';
$feature = $features[$feature];
$strings[] = $feature->info['name'];
if ($map = features_get_component_map('node')) {
foreach ($map as $node_type => $component_features) {
if (in_array($feature->name, $component_features)) {
node_types_clear();
$strings[] = node_type_get_name($node_type);
}
}
}
if ($map = features_get_component_map('views')) {
foreach ($map as $view_name => $component_features) {
if (in_array($feature->name, $component_features) && ($view = views_get_view($view_name, TRUE))) {
foreach (array_keys($view->display) as $display_id) {
$view
->set_display($display_id);
$strings[] = $view->display_handler
->get_option('title');
}
$view
->destroy();
}
}
}
if (module_hook($feature->name, 'menu')) {
$items = module_invoke($feature->name, 'menu');
foreach ($items as $path => $item) {
if (isset($item['title']) && strpos($path, 'features/') === FALSE && strpos($path, 'admin/') === FALSE) {
$strings[] = $item['title'];
}
}
}
$localized = array();
foreach ($strings as $string) {
$localized[] = module_exists('locale') ? locale($string, $langcode) : $string;
}
$language->language = $langcode;
}
return $strings;
}