Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291502

#children not populated when utilizing custom theme function in #theme for radios.

$
0
0

To reproduce this bug:

In a custom module:

  • Implement hook theme registering a my_module_radios function.
  • Create a form utilizing radios.
  • Populate the options array of the radios
  • Set the #theme value of the radios entry to use your custom theme function
  • Copy the implementation of theme_radios out of core or here https://api.drupal.org/api/drupal/includes!form.inc/function/theme_radios/7
  • Re-name it to so the name of the theme function matches what you defined in hook_theme and what you specified for #theme for the radios
  • Dump the value of $element['#children'] and it will be empty

function my_module_theme($existing, $type, $theme, $path) {
  return array(
    'my_module_radios' => array(
      'render element' => 'element',
    ),
    'my_module_radio' => array(
      'render element' => 'element',
    )
  );
}

$form['colors'] = array(
    '#type' => 'radios',
    '#title' => t('blah blah'),
    '#title_display' => 'attribute',
    '#options' => $options,
    '#default_value' => variable_get('colors_default', 0),
    '#required' => TRUE,
    '#theme' => 'my_module_radios',
  );

function theme_my_module_radios($variables) {
  $element = $variables['element'];
  $attributes = array();
  if (isset($element['#id'])) {
    $attributes['id'] = $element['#id'];
  }
  $attributes['class'] = 'form-radios';
  if (!empty($element['#attributes']['class'])) {
    $attributes['class'] .= '' . implode('', $element['#attributes']['class']);
  }
  if (isset($element['#attributes']['title'])) {
    $attributes['title'] = $element['#attributes']['title'];
  }
  return '<div' . drupal_attributes($attributes) . '>' . (!empty($element['#children']) ? $element['#children'] : '') . '</div>';
}

It appears other people have been experiencing a similar issue. I have found:

- https://drupal.org/node/1147888#comment-7539483
- https://drupal.org/node/497636
- https://drupal.org/node/1366922


Viewing all articles
Browse latest Browse all 291502

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>