Same as #2030869: Theme cannot add classes via preprocess webform date

Theme code

/**
 * Implements theme_preprocess_webform_time().
 */
function foo_preprocess_webform_time(&$variables) {
  // #2030885: Theme cannot add classes via theme_preprocess_webform_time().
  $variables['element']['hour']['#attributes']['class'][] = 'foo-inline';
  $variables['element']['minute']['#attributes']['class'][] = 'foo-inline';
  $variables['element']['ampm']['#attributes']['class'][] = 'foo-inline';

Broken code:

/**
 * Theme a webform time element.
 */
function theme_webform_time($variables) {
  $element = $variables['element'];

  $element['hour']['#attributes']['class'] = array('hour');
  $element['minute']['#attributes']['class'] = array('minute');

Bugfix:

/**
 * Theme a webform time element.
 */
function theme_webform_time($variables) {
  $element = $variables['element'];

  $element['hour']['#attributes']['class'][] = 'hour';
  $element['minute']['#attributes']['class'][] = 'minute';

Comments

hass’s picture

Issue summary: View changes

a

hass’s picture

Status: Active » Needs review
StatusFileSize
new859 bytes
hass’s picture

hass’s picture

Version: 7.x-3.9 » 7.x-3.x-dev

v3.19 was the start version

quicksketch’s picture

Priority: Major » Minor

Same as #2030869: Theme cannot add classes via preprocess webform date, I'm not sure we should change the class on these elements because it may break the CSS of existing sites. We can change the class in the 4.x branch if we desire, but I'm not sure if "form-select-hour" is really a necessity. You can already target the element accurately by using select.hour as the selector, which seems contextually like the "right" way to name your classes.

hass’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new836 bytes

Patch without class name changes.

hass’s picture

Please see #2029187: [meta] Make sure CSS classes are prefixed properly about such bad class names. All these class names should be prefixed with the module name to prevent theme classes. I'm fine with changing this in 4.x

hass’s picture

Needs to go into 4.x, too.

quicksketch’s picture

Title: Theme cannot add classes via theme_preprocess_webform_time » Append rather than override classes in theme_preprocess_webform_time()

Pushed to 7.x-3.x and 7.x-4.x. No ability to backport to 6.x-3.x since D6 uses strings for classes.

quicksketch’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

a