'Domain theme settings', 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'access arguments' => array('administer domains'), 'page callback' => 'domain_theme_page', 'page arguments' => array(4), 'file' => 'domain_theme.admin.inc', ); $items['admin/structure/domain/theme-reset/%domain'] = array( 'title' => 'Domain theme settings', 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'access arguments' => array('administer domains'), 'page callback' => 'domain_theme_reset', 'page arguments' => array(4), 'file' => 'domain_theme.admin.inc', ); $items['admin/structure/domain/theme/%/%domain/theme-settings'] = array( 'title' => 'Configure domain theme settings', 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'access arguments' => array('administer domains'), 'page callback' => 'domain_theme_settings', 'page arguments' => array(4, 5), 'file' => 'domain_theme.admin.inc', ); return $items; } /** * Implements hook_theme() */ function domain_theme_theme() { $themes = array( 'domain_theme_reset' => array( 'variables' => array('domain' => array()), ), 'domain_theme_form' => array( 'render element' => 'form', 'file' => 'domain_theme.admin.inc', ), ); return $themes; } /** * Get domain theme information * * @param $domain_id * The domain_id taken from {domain}. * @param $theme * The string representation of a {domain_theme} entry. Optional. * If this value is NULL, the default theme for this domain will be returned. * @param $reset * A boolean flag to clear the static variable if necessary. Not used. Here for consistency. * @return * An array containing the requested row from the {domain_theme} table. * Returns -1 on failure. */ function domain_theme_lookup($domain_id, $theme = NULL, $reset = FALSE) { if (!is_null($theme)) { $return = db_query("SELECT domain_id, theme, settings, status FROM {domain_theme} WHERE domain_id = :domain_id AND theme= :theme", array(':domain_id' => $domain_id, ':theme' => $theme))->fetchAssoc(); } else { $return = db_query("SELECT domain_id, theme, settings, status FROM {domain_theme} WHERE domain_id = :domain_id AND status = 1", array(':domain_id' => $domain_id))->fetchAssoc(); } if (empty($return)) { $return = -1; } return $return; } /** * Implements hook_domainlinks() */ function domain_theme_domainlinks($domain) { if ($domain['domain_id'] > 0) { $links[] = array( 'title' => t('theme'), 'path' => 'admin/structure/domain/theme/' . $domain['domain_id'] ); return $links; } return FALSE; } /** * Implements hook_domainform() */ function domain_theme_domainform(&$form) { // Set the module weight for Domain Theme, $module_weight = variable_get('domain_theme_weight', 0); db_update('system') ->fields(array('weight' => $module_weight)) ->condition('name', 'domain_theme') ->condition('type', 'module') ->execute(); // Add the form element to the main screen. $form['domain_theme'] = array( '#type' => 'fieldset', '#title' => t('Theme settings'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $options = drupal_map_assoc(array(-100, -25, -10, -5, -1, 0, 1, 5, 10, 25, 100)); $form['domain_theme']['domain_theme_weight'] = array( '#type' => 'select', '#title' => t('Domain Theme execution order'), '#options' => $options, '#default_value' => $module_weight, '#description' => t('If you use other modules that allow custom user or group themes, you may experience conflicts with the Domain Theme module. Use this setting to vary the execution order of the Domain Theme module. Lower (negative) values will execute earlier in the Drupal page building process.') ); } /** * Implements hook_domainbatch() */ function domain_theme_domainbatch() { $batch = array(); // Allows the deletion of all Domain Theme rows. $batch['domain_theme'] = array( '#form' => array( '#title' => t('Reset themes'), '#type' => 'checkbox', '#options' => array(0 => 1, 1 => t('Reset')), '#description' => t('Delete custom theme settings for this domain.'), ), '#permission' => 'administer themes', '#domain_action' => 'domain_delete', '#system_default' => 0, '#meta_description' => t('Delete custom theme settings for domains as supplied by Domain Theme.'), '#table' => 'domain_theme', '#weight' => -10, ); // Change themes for sites. $themes = list_themes(); $options = array(); foreach ($themes as $theme) { if ($theme->status == 1) { $options[$theme->name] = $theme->name; } } $batch['site_theme'] = array( '#form' => array( '#title' => t('Theme settings'), '#type' => 'select', '#options' => $options, '#description' => t('Select the theme for this domain.'), ), '#domain_action' => 'custom', '#lookup' => 'domain_theme_lookup', '#submit' => 'domain_theme_batch', '#system_default' => variable_get('theme_default', 'garland'), '#variable' => 'theme_default', '#meta_description' => t('Change the themes for all domains.'), '#data_type' => 'string', '#update_all' => TRUE, '#weight' => -9, ); foreach ($batch as $key => $value) { $batch[$key]['#module'] = t('Domain Theme'); } return $batch; } /** * Custom handler for domain_theme_domainbatch(). * * @param $values * The form values passed by the FormsAPI. */ function domain_theme_batch($values) { foreach ($values['domain_batch'] as $key => $value) { if ($key > 0) { // Clear out the old theme. db_query("UPDATE {domain_theme} SET status = 0 WHERE domain_id = %d", $key); $data = db_fetch_array(db_query("SELECT theme FROM {domain_theme} WHERE theme = '%s' AND domain_id = %d", $value, $key)); if (isset($data['theme'])) { db_query("UPDATE {domain_theme} SET status = 1 WHERE theme = '%s' AND domain_id = %d", $value, $key); } else { db_query("INSERT INTO {domain_theme} (domain_id, theme, status) VALUES (%d, '%s', 1)", $key, $value); } } else { variable_set('theme_default', $value); } } } /** * Implements hook_domainwarnings() */ function domain_theme_domainwarnings() { $forms = array( 'system_themes_form', 'system_theme_settings', ); $return = array(); foreach ($forms as $form) { $return[$form] = 'admin/structure/domain/theme/%domain_id'; } return $return; } /** * Return the unique string path element used by color.module. * * @param $path * A path to a color module file, such as 'default/files/garland-00123451/style.css'. * @ return * A string indicating the color module's filepath. */ function domain_theme_get_color_path($path) { return current(array_slice(array_reverse(explode('/', $path)), 1, 1)); } /** * Implements hook_form_alter(). * * This function is a helper to a normal hook_form_alter implementation, * where we add additonal form elemtns if we are dealing with domain-specific * form settings. */ 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(4); $domain_id = arg(5); $themes = list_themes(); $domain = domain_load($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); }