You are here

function themekey_ui_form_alter in ThemeKey 7

Same name and namespace in other branches
  1. 6.4 themekey_ui.module \themekey_ui_form_alter()
  2. 6 themekey_ui.module \themekey_ui_form_alter()
  3. 6.2 themekey_ui.module \themekey_ui_form_alter()
  4. 6.3 themekey_ui.module \themekey_ui_form_alter()
  5. 7.3 themekey_ui.module \themekey_ui_form_alter()
  6. 7.2 themekey_ui.module \themekey_ui_form_alter()

Implements hook_form_alter().

File

./themekey_ui.module, line 214
ThemeKey UI is an extension for ThemeKey

Code

function themekey_ui_form_alter(&$form, $form_state, $form_id) {
  if ('path_admin_form' == $form_id) {

    // path aliases form
    if (user_access('assign path alias themes') && variable_get('themekey_ui_pathalias', 0)) {
      module_load_include('inc', 'themekey_ui', 'themekey_ui_admin');
      themekey_ui_pathalias($form);
    }
  }
  elseif ('user_profile_form' == $form_id) {
    if (user_access('assign theme to own nodes') && variable_get('themekey_ui_author', 0)) {
      module_load_include('inc', 'themekey_ui', 'themekey_ui_admin');

      // to avoid a sql query to load his/her nodes' themes, every time a user is loaded, we do this query here
      $theme = FALSE;
      if (!empty($form['#user']->uid)) {
        $theme = db_select('themekey_ui_author_theme', 'tuat')
          ->fields('tuat', array(
          'theme',
        ))
          ->condition('uid', $form['#user']->uid)
          ->execute()
          ->fetchField();
      }
      themekey_ui_theme_select_form($form, t('Theme configuration for my nodes'), t('Every node I create will be shown to other users using this theme.'), $theme ? $theme : 'default');
    }
  }
  elseif ('themekey_help_tutorials_form' == $form_id) {
    module_load_include('inc', 'themekey_ui', 'themekey_ui_help');
    themekey_ui_help_tutorials($form);
  }
  else {

    // node form?
    if (variable_get('themekey_ui_nodeform', 0) && user_access('assign node themes')) {
      $type = isset($form['type']['#value']) ? $form['type']['#value'] : FALSE;
      if ($form_id == $type . '_node_form' && variable_get('themekey_ui_nodeform|' . $type, 1)) {
        module_load_include('inc', 'themekey_ui', 'themekey_ui_admin');
        $description = t('Theme configuration for this node');
        if (module_exists('og') && !og_is_omitted_type($type)) {
          $description .= '<p><b>' . t('Note:') . '</b> ' . t('This content type is used in Organic Groups. A theme you select here will only be used to display this node if you set the theme for the Organic Group to %theme', array(
            '%theme' => variable_get('theme_default', 'bartik') . ' ' . t('(site default theme)'),
          )) . '</p>';
        }
        themekey_ui_theme_select_form($form, t('Theme configuration for this node'), $description, !empty($form['#node']->themekey_ui_theme) ? $form['#node']->themekey_ui_theme : 'default');
      }
    }
  }
}