You are here

function content_theme_form_alter in Content Theme 6

Implementation of hook_form_alter().

File

./content_theme.module, line 205
This module allows to use different themes than the site default on content creating, editing, and viewing pages.

Code

function content_theme_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
    $edit_theme = isset($form['#node']->content_theme_content_node_edit) ? $form['#node']->content_theme_content_node_edit : '-content_type-';
    $view_theme = isset($form['#node']->content_theme_content_node_view) ? $form['#node']->content_theme_content_node_view : '-content_type-';
    $edit_access = user_access('select ' . $form['type']['#value'] . ' content editing theme');
    $view_access = user_access('select ' . $form['type']['#value'] . ' content viewing theme');

    // Add content node theme options to content node form.
    $form['content_theme'] = array(
      '#type' => 'fieldset',
      '#title' => t('Content theme settings'),
      '#description' => t('Applies only to this content node and overrides the content type themes, content wide themes, and the system default.'),
      '#collapsible' => TRUE,
      '#collapsed' => $edit_theme == '-content_type-' && $view_theme == '-content_type-',
      '#access' => $edit_access || $view_access,
      '#weight' => 20,
    );
    $form['content_theme']['content_theme_content_node_edit'] = array(
      '#type' => 'select',
      '#title' => t('Editing theme'),
      '#description' => t('Choose which theme the content creating and editing pages should display in. Content type theme: %content_type_theme; content wide theme: %content_wide_theme; system default theme: %system_default_theme.', array(
        '%content_type_theme' => content_theme_get_info_theme_name('content_type', 'edit', $form['type']['#value']),
        '%content_wide_theme' => content_theme_get_info_theme_name('content_wide', 'edit'),
        '%system_default_theme' => content_theme_get_info_theme_name(),
      )),
      '#default_value' => $edit_theme,
      '#options' => content_theme_get_content_node_options(),
      '#access' => $edit_access,
    );
    $form['content_theme']['content_theme_content_node_view'] = array(
      '#type' => 'select',
      '#title' => t('Viewing theme'),
      '#description' => t('Choose which theme the content viewing pages should display in. Content type theme: %content_type_theme; content wide theme: %content_wide_theme; system default theme: %system_default_theme.', array(
        '%content_type_theme' => content_theme_get_info_theme_name('content_type', 'view', $form['type']['#value']),
        '%content_wide_theme' => content_theme_get_info_theme_name('content_wide', 'view'),
        '%system_default_theme' => content_theme_get_info_theme_name(),
      )),
      '#default_value' => $view_theme,
      '#options' => content_theme_get_content_node_options(),
      '#access' => $view_access,
    );
  }
}