How to adapt #prefix/#suffix for each option in radio form using hook_form_alter()? I need to modify the html code of radio buttons generated by Ubercart Attributes. So I want to do it using hook_form_alter().



If I dsm() the $form I need to change using hook_form_alter() I get this

attributes (Array, 7 elements)
#theme (String, 24 characters ) uc_attribute_add_to_cart
#id (String, 42 characters ) uc_product_add_to_cart_form-472-attributes
    #type (String, 6 characters ) radios
    #default_value (NULL)
    #options (Array, 4 elements)
        0 (String, 7 characters ) Color 1
        1 (String, 7 characters ) Color 2
        2 (String, 7 characters ) Color 3
        3 (String, 8 characters ) Color 17
    #ajax (Array, 2 elements)
    #title (String, 4 characters ) yeah
    #description (String, 0 characters )
    #required (String, 1 characters ) 1


I can apply a #prefix/#suffix to div wrapping all radio buttons:

&lt;div class="test"&gt;
  &lt;div class="form-item form-type-radios form-item-attributes-8"&gt;
     &lt;div class="form-label"&gt;
        &lt;div class="element-inner"&gt;
           &lt;div class="el"&gt;
               &lt;div id="edit-attributes-8" class="form-radios my-custom-class"&gt;
               &lt;div class="form-item form-type-radio form-item-attributes-8"&gt;
               &lt;div class="form-item form-type-radio form-item-attributes-8"&gt;
               &lt;div class="form-item form-type-radio form-item-attributes-8"&gt;
              &lt;div class="form-item form-type-radio form-item-attributes-8"&gt;
           &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="description"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
 &lt;/div&gt;


I proceed like that for this result:

$form['attributes']['8']['#prefix'] = '&lt;div class="test"&gt;';
$form['attributes']['8']['#suffix']= '&lt;/div&gt;'; 


The problem is that I want to apply this #prefix/#suffix to all options instead, I tried something like that but it doesn't work:

$form['attributes']['8']['#options'][0]['#prefix'] = '&lt;div class="test"&gt;';
$form['attributes']['8']['#options'][0]['#suffix']= '&lt;/div&gt;'; 


So is it possible to do it this way? Any suggestion?
In your form_alter you can tell drupal to use your custom theme_radio like this:

$form['attributes']['#theme'] = 'MYCUSTOM_radio_theme';


Then in 'MYCUSTOM_radio_theme:

$element = $variables['element'];


$element['#attributes']['type'] = 'radio';



element_set_attributes($element, array('id', 'name','#return_value' =&gt; 'value'));



if (isset($element['#return_value']) &amp;&amp; $element['#value'] !== FALSE &amp;&amp; $element['#value'] == $element['#return_value']) {
    $element['#attributes']['checked'] = 'checked';



}
  _form_set_class($element, array('form-radio'));

  return '&lt;div class="test"&gt;&lt;input' . drupal_attributes($element['#attributes']) . ' /&gt;&lt;/div&gt;';