function domain_theme_form_alter in Domain Access 7.3
Same name and namespace in other branches
- 5 domain_theme/domain_theme_form.inc \domain_theme_form_alter()
- 6.2 domain_theme/domain_theme.admin.inc \domain_theme_form_alter()
- 7.2 domain_theme/domain_theme.module \domain_theme_form_alter()
Implements hook_form_alter().
This function is a helper to a normal hook_form_alter implementation, where we add additional form elements if we are dealing with domain-specific form settings.
File
- domain_theme/
domain_theme.module, line 238 - Domain Theme module for the Domain Access module group.
Code
function domain_theme_form_alter(&$form, &$form_state, $form_id) {
// We cannot use a named form_alter here because of color module.
// Color submit must happen first, and a named function destroys that.
if ($form_id != 'system_theme_settings' || arg(2) != 'domain') {
return;
}
$theme = arg(6);
$domain_id = arg(4);
$themes = list_themes();
$domain = domain_lookup($domain_id);
if ($domain == -1 || !array_key_exists($theme, $themes)) {
return drupal_access_denied();
}
// Which domain are we editing?
$form['domain_id'] = array(
'#type' => 'value',
'#value' => $domain['domain_id'],
);
$form['theme'] = array(
'#type' => 'value',
'#value' => $theme,
);
// We have to remove the core submit handler, but keep other handlers.
// Otherwise, our changes get saved to the {variables} table.
$form['#submit'][100] = 'domain_theme_settings_submit';
foreach ($form['#submit'] as $key => $value) {
if ($value == 'system_theme_settings_submit') {
unset($form['#submit'][$key]);
}
}
// Check for the presence of color.module. If it exists, we have to account
// for it and run a check to ensure we don't delete the main site's theme
// folder if we set a domain theme to the default scheme.
$color_info = NULL;
if (module_exists('color') && ($color_info = color_get_info($theme))) {
$form['#submit'][-100] = 'domain_theme_color_submit';
}
// Order of operation becomes:
// domain_theme_color_submit()
// color_form_submit()
// domain_theme_settings_submit()
ksort($form['#submit']);
// If no color module, we are done.
if (empty($color_info)) {
return;
}
// Label the scheme correctly.
// Since may have added a 'domain_default' element to the palette,
// color module might think we are not using the default theme.
$current_scheme = variable_get('color_' . $theme . '_palette', array());
if (isset($current_scheme['domain_default'])) {
unset($current_scheme['domain_default']);
$info = color_get_info($theme);
if (isset($info['schemes']['default']['colors']) && implode(',', $info['schemes']['default']['colors']) == implode(',', $current_scheme)) {
$form['color']['scheme']['#default_value'] = 'default';
}
}
// Color module will reset the values in {variable}. which we don't
// want to happen. So we have to grab the existing values and store
// them so that we can set the {variable} table correctly.
// TODO: Make this work with Domain Prefix.
$vars = array(
'palette',
'stylesheets',
'logo',
'files',
'screenshot',
);
foreach ($vars as $variable) {
$name = 'color_' . $theme . '_' . $variable;
$value = db_query("SELECT value FROM {variable} WHERE name = :name", array(
':name' => $name,
))
->fetchField();
$color_settings[$name] = isset($value) ? $value : NULL;
}
$form['domain_color_defaults'] = array(
'#type' => 'value',
'#value' => $color_settings,
);
}