You are here

function _themekey_settings_form in ThemeKey 6

Function _themekey_settings_form().

1 string reference to '_themekey_settings_form'
themekey_menu in ./themekey.module
Implementation of hook_menu().

File

./themekey_admin.inc, line 253

Code

function _themekey_settings_form() {

  //
  _themekey_rebuild();

  //
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('General Settings'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $form['settings']['themekey_allthemes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide all themes for selection'),
    '#default_value' => variable_get('themekey_allthemes', 1),
    '#description' => t('Make all installed themes available for selection, not enabled ones only.'),
  );
  $form['settings']['themekey_theme_maintain'] = array(
    '#type' => 'checkbox',
    '#title' => t('Retain the theme until a new theme is set'),
    '#default_value' => variable_get('themekey_theme_maintain', 0),
    '#description' => t('Select this option to have users stay in the same theme until they
                         browse to a new page with an explicit theme set.'),
  );
  $nodediscover = variable_get('themekey_nodediscover', 0);
  $form['settings']['themekey_nodediscover'] = array(
    '#type' => 'checkbox',
    '#title' => t('Discover all node properties for selection'),
    '#default_value' => $nodediscover,
    '#description' => t('Allows you to assign themes to node properties (e.g. type, status, uid, ...).'),
  );
  $form['settings']['properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('Properties'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['settings']['properties']['table'] = array(
    '#theme' => 'themekey_table',
    '#header' => array(
      t('Property'),
      t('Description'),
      t('Enabled'),
      t('Weight'),
      '',
    ),
    '#tree' => TRUE,
  );

  //
  $config = variable_get('themekey_properties', array());
  $attributes = variable_get('themekey_attributes', array());
  $properties = _themekey_properties_discover($nodediscover);
  foreach ($properties as $property => $path) {
    $properties[$property] = array(
      'path' => $path,
      'property' => $property,
      'enabled' => isset($config[$property]),
      'weight' => isset($config[$property]) ? $config[$property]['weight'] : 0,
    );
  }

  //
  uasort($properties, '_themekey_properties_cmp');
  foreach ($properties as $property => $details) {
    $form['settings']['properties']['table'][$property]['property'] = array(
      '#value' => $property,
    );
    $form['settings']['properties']['table'][$property]['description'] = array(
      '#value' => isset($attributes[$property]['description']) ? $attributes[$property]['description'] : '-',
    );
    $form['settings']['properties']['table'][$property]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => '',
      '#default_value' => $details['enabled'],
    );
    $form['settings']['properties']['table'][$property]['weight'] = array(
      '#type' => 'weight',
      '#title' => '',
      '#default_value' => $details['weight'],
    );
    $form['settings']['properties']['table'][$property]['path'] = array(
      '#type' => 'hidden',
      '#value' => $details['path'],
    );
  }

  //
  if (isset($properties['nid']) && $properties['nid']['enabled']) {
    $form['settings']['additional']['themekey_nodeaspath'] = array(
      '#type' => 'select',
      '#title' => t('Node theme preference'),
      '#options' => array(
        0 => t('Property-based'),
        1 => t('Path-based'),
      ),
      '#default_value' => variable_get('themekey_nodeaspath', 0),
      '#description' => t('By default node themes are stored as nid property values. If you are working with path aliases it might be
                           better to store them as paths. You should not change this settings once you have existing items.'),
    );
    if (_themekey_num_paths() > 0) {
      $warning = '<br /><strong class="error">';
      $warning .= t('WARNING: Do not change this settings or you will get duplicate (mixed) assignment to paths and properties.');
      $warning .= '</strong>';
      $form['settings']['additional']['themekey_nodeaspath']['#description'] .= $warning;
    }
  }

  //
  if (isset($form['settings']['additional']) && count($form['settings']['additional'])) {
    $form['settings']['additional'] += array(
      '#type' => 'fieldset',
      '#title' => t('Additional Settings'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
  }
  return _themekey_admin_form($form, '_themekey_settings', FALSE);
}