You are here

function delta_create_theme_settings_template_form in Delta 6

Same name and namespace in other branches
  1. 7 delta.module \delta_create_theme_settings_template_form()

Form callback for the AJAX form using Popups API

Parameters

$form_state:

$theme:

1 string reference to 'delta_create_theme_settings_template_form'
delta_create_theme_settings_template in ./delta.module
Page callback for AJAX implementation of the add template form

File

./delta.module, line 955
The Delta Theme API is an advanced manipulation of the Theme Settings API to allow for customization/configuration of theme settings based on node types, context, or groups of paths.

Code

function delta_create_theme_settings_template_form($form_state, $theme) {
  $form = array();
  $form['info'] = array(
    '#value' => t('Create a new Theme Settings Template for the <strong><em>' . $theme . '</em></strong> theme.'),
  );
  $form['delta_template'] = array(
    '#type' => 'fieldset',
    '#title' => t('General Template Information'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $form['delta_template']['theme'] = array(
    '#type' => 'hidden',
    '#value' => $theme,
  );
  $form['delta_template']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Theme Settings Template Title'),
    '#required' => FALSE,
    '#default_value' => $form_state['delta_template']['name'],
    '#description' => t('Use a descriptive title to name your theme settings template.'),
  );
  $form['delta_template_overrides'] = array(
    '#type' => 'fieldset',
    '#title' => t('Theme Settings to Override.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );

  /**
   * Let's look to locate a theme-settings.php file for the theme we are
   * creating the template for.
   * Once we have the file, we can included it and load the function
   */
  if (file_exists(drupal_get_path('theme', $theme) . '/theme-settings.php')) {
    include_once drupal_get_path('theme', $theme) . '/theme-settings.php';
    if (function_exists($theme . '_settings')) {
      $function = $theme . '_settings';
    }
    elseif (function_exists('phptemplate_settings')) {
      $function = 'phptemplate_settings';
    }
    else {

      // @todo let's put in a check if both these functions don't exist, and throw fat errors.
    }
    $settings = theme_get_settings($theme);
    $override_form_elements = $function($settings);
    foreach ($override_form_elements as $k => $v) {
      $form['delta_template_overrides'][$k] = $v;
    }
  }

  // submit button
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Template'),
    '#validate' => array(
      'delta_create_theme_settings_template_validate',
    ),
    '#submit' => array(
      'delta_create_theme_settings_template_submit',
    ),
  );
  $form['#redirect'] = 'admin/build/delta/settings/' . $theme;
  return $form;
}