0

I have read similar questions on here, but I'm still struggling for an answer for this.

I'm trying to implement hook_bootstrap_colorize_text() to alter button colors in a Bootstrap sub-theme.

I would like to add some specific text items to the array that dictates how the buttons are colorizes. For example, I have some buttons that have the "btn-default" class, and I would like to indicate specific texts to which should have “btn-success" or "btn-warning" instead.

The bootstrap.api.php describes this process:

/**
 * Allows sub-themes to alter the array used for colorizing text.
 * …
 * @see _bootstrap_colorize_text()
 */
 function hook_bootstrap_colorize_text_alter(array &$texts) {
   // This matches the exact string: "My Unique Button Text".
   $texts['matches'][t('My Unique Button Text')] = 'primary';

  // This would also match the string above, however the class returned would
  // also be the one above; "matches" takes precedence over "contains".
  $texts['contains'][t('Unique')] = 'notice';

  // Remove matching for strings that contain "apply":
  unset($texts['contains'][t('Apply')]);

  // Change the class that matches "Rebuild" (originally "warning"):
  $texts['contains'][t('Rebuild')] = 'success';
}

Therefore, I have attempted to implement the following code in my sub-theme (methodsTheme) template.php file without success.

<?php
// Implements hook_bootstrap_colorize_text_alter() to alter button colors.
  function methodstheme_bootstrap_colorize_text_alter(array &$texts) {
    $texts['matches'][t('Request Rotation')] = 'success';
    $texts['contains'][t('Notify')] = 'success';
    $texts['contains'][t('Set')] = 'success';
    $texts['contains'][t('Mark')] = 'success';
    $texts['contains'][t('Assign')] = 'success';
    $texts['contains'][t('Report')] = 'warning';
    $texts['contains'][t('Request')] = 'info';
  }
?>

I've also tried:

<?php
// Implements hook_bootstrap_colorize_text_alter() to alter button colors.
  function methodstheme_bootstrap_colorize_text_alter(&$texts) {
    $texts['matches'][t('Request Rotation')] = 'success';
    $texts['contains'][t('Notify')] = 'success';
    $texts['contains'][t('Set')] = 'success';
    $texts['contains'][t('Mark')] = 'success';
    $texts['contains'][t('Assign')] = 'success';
    $texts['contains'][t('Report')] = 'warning';
    $texts['contains'][t('Request')] = 'info';
  }
?>

And, I've also tried:

<?php
// Implements hook_bootstrap_colorize_text_alter() to alter button colors.
  function methodstheme_bootstrap_colorize_text_alter(&$texts) {
    $texts = array(
      'matches' => array(
        t('Request Rotation') => 'success',
      ),
      'contains' => array(
        t('Notify') => 'success',
        t('Set') => 'success',
        t('Mark') => 'success',
        t('Assign') => 'success',
        t('Report') => 'warning',
        t('Request') => 'info',
      ),
    );
  }
?>

And, yes, after each attempt, I'm clearing the caches to see if the changes to the code are implemented to the desired result. However, I'm still emptyhanded. I'm placing the template.php file in my sites/all/themes/methodstheme/templates folder. The sub-theme was already established and working well (i.e., it is set-up properly, I believe).

I'm using Drupal 7.64 (with install profile varbase, but I've mostly removed all usage of the varbase profile and modules) and latest version of Bootstrap 3 theme as the base theme.

Can anyone offer some help or suggestions on what the issue may be?

2
  • How do you output your buttons? Mar 9, 2019 at 20:04
  • Sorry for omitting that information - I am using Views Bulk Operations. I have several different pages of views, many of which have VBO fields with the operations rendered as buttons. Mar 10, 2019 at 13:59

1 Answer 1

2

Well, I really thought I had tried everything before posting. I didn't think I'd be answering my own question, but I'll put it up here in the case it is helpful to others. Here is what eventually worked for me:

<?php
  //Implements hook_bootstrap_colorize_text_alter() to alter Bootstrap button colors.
  function methodstheme_bootstrap_colorize_text_alter(&$texts) {
    $texts['matches'][t('Request Rotation')] = 'success';
    $texts['contains'][t('Notify')] = 'success';
    $texts['contains'][t('Set')] = 'success';
    $texts['contains'][t('Mark')] = 'success';
    $texts['contains'][t('Assign')] = 'success';
    $texts['contains'][t('Report')] = 'warning';
    $texts['contains'][t('Request')] = 'info';
  }
?>

I had tried this earlier, and had no result after clearing caches. I had tried placing the template.php file in my sites/all/themes/methodstheme/templates folder as well as the sites/all/themes/methodstheme (not the templates sub-folder) folder.

Regardless of the folder I placed it in, it was still not working - I had no result after clearing the caches initially.

Placing the file in the sites/all/themes/methodstheme (not the templates sub-folder) folder was part of the solution. I had brushed up on the Bootstrap Starterkit file structure, and I was fairly certain the template.php file should not be in the templates sub-folder, so I started trying other things. Using Drush I cleared the theme-registry cache, the theme list cache, then cleared all caches. I cleared those caches again a second time, and viola! My site is now functioning as expected.

Lesson learned - clearing caches multiple times is sometimes necessary/helpful!

Your Answer

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

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