2

I've set up Color module for my theme - it works pretty well, but takes too much vertical space (I have a bunch of colors). What i'm trying to do is to alter system-theme-settings form to make Color scheme fieldset collapsible. So here's my code:

function test_form_system_theme_settings_alter(&$form, &$form_state) {
  drupal_set_message('DEBUG: ' . print_r($form['logo'], 1));
  // Above line prints array of logo settings - so function works well

  drupal_set_message('DEBUG: ' . print_r($form['color'], 1));
  /* This line prints nothing and I get:
   * 'Notice: Undefined index: color in test_form_system_theme_settings_alter()
   * (line 16 of /var/www/sites/all/themes/test/theme-settings.php).'
   */
}

As you can see, i can't alter $form['color'] because it doesn't exist. Here's the color_form_system_theme_settings_alter function.

Am i missing something?

2 Answers 2

3

Definitly system-theme-settings is a core form where color module adding its fields using hook_form_alter in the same manner you are doing.

The point at which your hook_form_alter is invoked seems to be earlier then the color module's.

Check out hook_module_implements_alter to alter the registry of modules implementing a hook.

1
  • What if you want your theme to alter the color module $form fieldset? The hook you described only lets module hooks to be re-ordered and not themes
    – wiifm
    Commented Jul 27, 2011 at 2:33
2

If you want theme to alter the color fieldset, you will need to use the #process variable.

For instance:

function YOURTHEME_form_system_theme_settings_alter(&$form, &$form_state) {
  $form['#process'][] = 'YOURTHEME_make_collapsible'
}

function YOURTHEME_make_collapsible($form) {
  $form['color']['#collapsible'] = TRUE;
  $form['color']['#collapsed'] = TRUE;

  return $form;
}

Functions defined in the #process variable will run after modules have done their altering. Therefore, you can access $form['color'] and alter it from theme's theme-settings.php.

1
  • fyi this works in D8 also.
    – Jeff Burnz
    Commented Aug 12, 2014 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.