Looking at theme_fieldset
the fieldset-wrapper
class is hardcoded and that div doesn't take any additional classes from the $variables
array.
So looks like the only option is to override theme_fieldset
in your template.php
of the active theme. If your conditional variables are present in $variables
then you could do the logic straight in the theme_fieldset
override function (replace mythemename
with the name of your theme)
function mythemename_fieldset($variables) {
$element = $variables['element'];
element_set_attributes($element, array('id'));
_form_set_class($element, array('form-wrapper'));
$output = '<fieldset' . drupal_attributes($element['#attributes']) . '>';
if (!empty($element['#title'])) {
// Always wrap fieldset legends in a SPAN for CSS positioning.
$output .= '<legend><span class="fieldset-legend">' . $element['#title'] . '</span></legend>';
}
// Condition/logic here
$class = '';
if($variables['....'] == '....') {
$class = ' well-small';
}
$output .= '<div class="fieldset-wrapper'.$class.'">';
if (!empty($element['#description'])) {
$output .= '<div class="fieldset-description">' . $element['#description'] . '</div>';
}
$output .= $element['#children'];
if (isset($element['#value'])) {
$output .= $element['#value'];
}
$output .= '</div>';
$output .= "</fieldset>\n";
return $output;
}
Otherwise, a more elegant solution (by @Mołot) would be to supply use drupal_attributes
like so:
mythemename_fieldset(&$variables) {
$element = $variables['element'];
element_set_attributes($element, array('id'));
_form_set_class($element, array('form-wrapper'));
$output = '<fieldset' . drupal_attributes($element['#attributes']) . '>';
if (!empty($element['#title'])) {
// Always wrap fieldset legends in a SPAN for CSS positioning.
$output .= '<legend><span class="fieldset-legend">' . $element['#title'] . '</span></legend>';
}
$element['#wrapper-attributes']['class'][] = 'fieldset-wrapper';
$output .= '<div' . drupal_attributes($element['#wrapper-attributes']) . '">';
if (!empty($element['#description'])) {
$output .= '<div class="fieldset-description">' . $element['#description'] . '</div>';
}
$output .= $element['#children'];
if (isset($element['#value'])) {
$output .= $element['#value'];
}
$output .= '</div>';
$output .= "</fieldset>\n";
return $output;
}