expand_radios

Versions
4.7 – 6
expand_radios($element)

Roll out a single radios element to a list of radios, using the options array as index.

Related topics

Code

includes/form.inc, line 1263

<?php
function expand_radios($element) {
  if (count($element['#options']) > 0) {
    foreach ($element['#options'] as $key => $choice) {
      if (!isset($element[$key])) {
        // Generate the parents as the autogenerator does, so we will have a
        // unique id for each radio button.
        $parents_for_id = array_merge($element['#parents'], array($key));
        $element[$key] = array(
          '#type' => 'radio',
          '#title' => $choice,
          '#return_value' => check_plain($key),
          '#default_value' => $element['#default_value'],
          '#attributes' => $element['#attributes'],
          '#id' => form_clean_id('edit-'. implode('-', $parents_for_id)),
          '#parents' => $element['#parents'],
          '#spawned' => TRUE
        );
      }
    }
  }
  return $element;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.