current code:

$function = $key .'_settings';
$group = $function($settings);
$form['theme_specific'] = array_merge($form['theme_specific'], $group);

so, if themename_settings contains $form['#submit'],
that ends up in $form['theme_specific']['#submit'] not $form['#submit'] as expected
thus breaking custom #submit handlers and i would imagine #validate, #after_build handlers and #redirect and #theme overrides.

This is critical because it wastes time of developers,
who have been clearly told they can use standard forms API, but can't. :(

Comments

treksler’s picture

StatusFileSize
new1.74 KB

quick patch that fixes the submit handler by applying any keys starting with a '#' above the 'theme_specific' fieldset

treksler’s picture

StatusFileSize
new1.75 KB

oops typo

treksler’s picture

StatusFileSize
new1.64 KB

Cleaner patch without duplication

treksler’s picture

Of course another way to fix it would be to get rid of the 'theme_specific' and 'engine_specific' fieldsets, which IMO should be considered, since AFAICS Drupal 7 does not have them.

treksler’s picture

here's a patch that just eliminates the fieldset .. if people want their overrides to be in a fieldset, they can make one in theme-settings.php .. this gives them more control over the name of the fieldset as well without requiring a theme override in template.php .. this also simplifies adding custom settings into existing fieldsets .. eg breadcrumb display into 'Toggle display' and a logo link into the 'logo image settings' .. and like i said in my previous comment, as far as i know, this is the way Drupal 7 does it.

treksler’s picture

StatusFileSize
new1.25 KB

oops, forgot to attach patch

treksler’s picture

StatusFileSize
new1.21 KB

actually, Drupal 7 seems to call a form alter for theme specific AND for engine specific settings, so no separate 'theme_specific' or 'engine_specific' fieldset is required, but Drupal 7 creates an 'engine_specific' fieldset anyway, but does not stuff anything in there by default.

treksler’s picture

Status: Needs review » Active
StatusFileSize
new2.57 KB

here's the latest patch that aims to be more forward compatible with Drupal 7 .. I basically turn the settings into a real form alter ..

note1: foo_settings($settings) becomes foo_form_system_theme_settings_alter($form_id, &$form) in Drupal 5
note2: the form alter is responsible for getting the settings (see below for an example)
note3: the form alter is responsible for adding any fieldset (there isn't one built in anymore)
note4: all submit handlers just work :))

<?php
function foo_form_system_theme_settings_alter($form_id, &$form) {

  // Get the theme settings & merge the saved variables and their default values
  $settings = foo_get_settings();

  $form['foo'] = array(
    '#type' => 'fieldset',
    '#title' => t('Foo template settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => -10,
  );

  $form['foo']['bar'] = array(
    '#type' => 'select',
    '#title' => t('Theme Level'),
    '#default_value' => $settings['bar'],
    '#options' => array (
      'a' => 'Level A ',
      'b' => 'Level B',
    ),
  );

  $form['foo']['logo_link'] = array(
    '#type' => 'textfield',
    '#title' => t('Logo Link'),
    '#description' => t('Website that the logo links to'),
    '#default_value' => $settings['logo_link'],
  );

  $form['#submit']['foo_submit'] = array();
}

function foo_submit($form_id, $form_values) {
 
  // some code to handle uploads or to generate a custom css override based on extra settings

  return;
}

function foo_get_settings() {

  static $settings;
  if (!$settings) {
    $defaults = foo_get_defaults();
    $saved_settings = theme_get_settings('foo');
    $settings = array_merge($defaults, $saved_settings);
  }

  return $settings;
}

function foo_get_defaults() {
  static $defaults;
  if (!$defaults) {
    $defaults = array(
      'bar' => 'b',
      'logo_link' => 'http://www2.foo.com/',
    );
  }
  return $defaults;
}
?>
treksler’s picture

Status: Active » Needs review
pomliane’s picture

Status: Active » Closed (won't fix)

This version of Theme Settings API is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.