I have a Bootstrap 3 subtheme with the iconize buttons and colorize buttons settings activated.

For node forms etc the iconize buttons and colorize button functions work as expected.

For Views Bulk Operations forms the colorize function runs for action buttons but the iconize function does not.

Comments

derekw created an issue. See original summary.

markhalliwell’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

If the button text doesn't contain one of the following, it doesn't add an icon:
https://drupal-bootstrap.org/api/bootstrap/includes%21common.inc/functio...

If you need/want to add additional icons, you can do so via hook_bootstrap_iconize_text_alter() in your sub-theme.

derekw’s picture

Yes I did test that. For instance a button labeled Delete is one of the action buttons. It will get colorized but no Icon. Probably because button.vars.php only has _bootstrap_colorize_button($element), not _bootstrap_iconize_button.

So I added a theme_preprocess_button function in my template.php which just copied the button.vars.php but added _bootstrap_iconize_button. So far so good, icons are now showing on VBO buttons.

//add class and icons to buttons
function mytheme_preprocess_button(&$vars){
  $element = &$vars['element'];

  // Drupal buttons should be of type 'submit'.
  // @see https://www.drupal.org/node/2540452
  $element['#attributes']['type'] = 'submit';

  // Set the element's other attributes.
  element_set_attributes($element, array('id', 'name', 'value'));

  // Add the base Bootstrap button class.
  $element['#attributes']['class'][] = 'btn';

  // Add button size, if necessary.
  if ($size = bootstrap_setting('button_size')) {
    $element['#attributes']['class'][] = $size;
  }

  // Colorize button.
  _bootstrap_colorize_button($element);

  // Iconize button.
  _bootstrap_iconize_button($element);

  // Add in the button type class.
  $element['#attributes']['class'][] = 'form-' . $element['#button_type'];

  // Ensure that all classes are unique, no need for duplicates.
  $element['#attributes']['class'] = array_unique($element['#attributes']['class']);
}
markhalliwell’s picture

Title: iconize doesn't run, colorize does for VBO form buttons » Buttons only get iconized if in a form and part of actions
Version: 7.x-3.11 » 7.x-3.x-dev
Category: Support request » Bug report
Priority: Normal » Critical
Status: Closed (works as designed) » Active

Hmm... wow... I have no idea how that oversight happened!

You're right. It's only invoked in two places:

  • bootstrap_form_process() - for relocating buttons to input groups (like the search button)
  • bootstrap_form_process_actions() - for form actions likely saving a node

That's really, really odd.

Yes, this should be invoked in bootstrap_preprocess_button() because, as it stands now, it's would only ever be added if the element is in a form and an action button.

Sorry for closing the issue so abruptly, thought it was "some random button doesn't have text".

---

My only concern is that adding this may make some consider this a "break" if icons just start to randomly show up.

That being said, considering that this functionality is already in InputButton::preprocessElement (a.k.a HOOK_preprocess_input__button), this should just be fixed some it's consistent.

I'll commit a fix shortly.

  • markcarver committed f00d017 on 7.x-3.x authored by derekw
    Issue #2854933 by derekw: Buttons only get iconized if in a form and...
markhalliwell’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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