0

I am working on a site with Drupal commerce, I use the Bootstrap theme and a child theme.
I would like the [add-to-cart] button to have the "btn-default" class, instead of “btn-success". Actually, I want to get rid of the "info" and "warning" classes in many cases where I don't need them and replace them by "default" or "primary".

I saw in /sites/all/themes/bootstrap/bootstrap.api.php

/**
 * 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';
}

So I tried in /sites/all/themes/[my-sub-theme]/template.php

function hook_[my-sub-theme]_colorize_text_alter(array &$texts) {
  // Let's try a dummy change for a test
  $texts['contains'][t('Update cart')] = 'success';
}

But I can't see anything changed.

I also saw that /sites/all/themes/bootstrap/includes/common.inc sets a number of values based on the contained string, in which I find th “Update” I am looking for. the function is
function _bootstrap_colorize_text($string, $default = '') {…}
it ends with

// Allow sub-themes to alter this array of patterns.
    drupal_alter('bootstrap_colorize_text', $texts);

But I still haven't found how to do what I want in my sub theme. and what I read in /sites/all/themes/bootstrap/templates/system/buttons.vars.php won't help me.

Can somebody please explain where to start?

1

I'm having the same type of issue (which I will post elsewhere). I'm not sure I have the best answer, but from what I read in the Bootstrap API documentation, I believe your code should read as follows.

function [my-sub-theme]_colorize_text_alter(array &$texts) {
  // Let's try a dummy change for a test
  $texts['contains'][t('Update cart')] = 'success';
}

The preceding "hook" needs to be entirely replaced by your [my-sub-theme] name. From what I read, that should be what is needed for this to work. However, I'm having trouble getting it to work myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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