I'm using 7.x-3.0 rather than 7.x-3.x-dev or 7.x-3.1-beta2 because those white screen on me as soon as enabled and it's the recommended release.

In any case, I'm using a basic subtheme-- so far it's identical to the starterkit subtheme provided by the theme. This is the first modification I'm trying to make. I'm trying to change the class on the default search block form button to btn-primary (currently it's getting btn-default) and for the life of me I can't seem to figure out the correct method.

I've tried the standard hook_form_alter as well as theme_preprocess_button and neither seems to have any effect.

Any hints would be greatly appreciated.

Comments

WorldFallz’s picture

Also weird-- if I try to override search-block-form.tpl.php and dump $form['actions']['submit']['#attributes']['class'] it IS getting btn-primary-- but the rendered button is 'btn-default' when i view the source of the page.

markhalliwell’s picture

Version: 7.x-3.0 » 7.x-3.x-dev
Status: Active » Fixed
Related issues: +#2098551: Registry alter does not keep proper order of [pre]process functions

With the recent commit in the related issue, you should now be able to do something like the following since the bootstrap preprocess now runs first (which now adds the button class before your sub-theme would):

function bootstrap_subtheme_preprocess_button(&$variables, $hook) {
  $key = array_search('btn-primary', $variables['element']['#attributes']['class']);
  if ($key !== FALSE) {
    unset($variables['element']['#attributes']['class'][$key]);
    $variables['element']['#attributes']['class'][] = 'btn-default';
  }
}

That being said, this is still more of a "hack" IMO or should only be used if you really want to affect all buttons with the 'btn-primary' class.

The more "appropriate way" or for a "one off" type of case, you should do a form alter on where the button is actually constructed and add the class there. _bootstrap_colorize_button() will not add a button class if one already exists:

function bootstrap_subtheme_form_FORM_ID_alter(&$form, &$form_state) {
  $form['actions']['submit']['#attributes']['class'][] = 'btn-default';
}

Although, the real "proper way" would be to use the hook_bootstrap_colorize_text_alter() hook in the API to alter the arrays of text that is used to match text with colors (there is also one for icons). This ensures that all the buttons are consistent throughout the site, regardless of the form.

/**
 * Implements hook_bootstrap_colorize_text_alter().
 */
function bootstrap_subtheme_bootstrap_colorize_text_alter(&$texts) {
  $texts['matches'][t('Search')] = 'default';
}
WorldFallz’s picture

This is completely weird, lol. I've tried ALL the methods you suggested (with the patch from #2098551: Registry alter does not keep proper order of [pre]process functions) and none of them seem to be changing the search_block_form button to the btn-default.

I'm out of time for today, but I'll try and test some other buttons to see if it's a search button specific issue.

And I'll try some other overrides for the linked patch as well.

And brilliant-- the last 2 suggestions are much better methods.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

alanom’s picture

Status: Closed (fixed) » Active

Like Worldfallz, I'm having the same problem. All the above methods result in no change to the actual button. I've confirmed the variables change, but the actual output remains unchanged.

For me, I'm trying to change the search button text, and whether I use the form or button hook, no changes to the array actually change the output.

markhalliwell’s picture

Status: Active » Closed (fixed)
alanom’s picture

Two out of two people reporting that the suggested solution to a problem doesn't work for them isn't enough?

If what you mean is, that it works in most cases, and the maintainers can't do anything without more information about what me and Worldfallz are doing differently, that's what "Postponed (maintainer needs more info)" is for.

Anonymous’s picture

Old thread again but maybe somebody else is reading these too.

I had no problems changing class of a button for a specific form with instructions from #2.

In mysubtheme template.php:

function mysubtheme_form_FORM_ID_alter(&$form, &$form_state) {
  $form['actions']['submit']['#attributes']['class'][] = 'btn-success';
}