0

I have this code inside mymodule_form_alter:

     foreach ($form['attributes'] as $att) {
        foreach ($att['#options'] as $option => $value) {
  // Get the name of the option without the price or price adjustment -> string before coma
            $optionName = explode(",", $att['#options'][$option], 2)[0];
            if (strpos($optionName, '+') !== false) {
                $att['#options'][$option]['#attributes'][] = array('class' => array('my_class'));
            }
        }
    }

Unfortunately

$att['#options'][$option]['#attributes'][] = array('class' => array('my_class'));

Displays unexpected error, I tried different syntax but no success. Any help much appreciated

Update 27/09/2017

I tried to do this by using after_build I get no errors but it isn't working

// Inside hook_form_alter
 $form['attributes']['#after_build'][] = 'addToCartFormEditQuantity_after_build';

 function addToCartFormEditQuantity_after_build(&$element, &$form_state)
{
    // Each renderable radio element.
    foreach ($element as $attribute) {
        foreach (element_children($attribute) as $option) {
            var_dump($attribute[$option]);
      // Get the name of the option without the price or price adjustment -> string before coma
            $optionName = explode(",", $attribute['#options'][$option], 2)[0];
            if (strpos($optionName, '+') !== false) {
                $attribute[$option]['#atrributes']['class'] .= 'single-double';
            }
        }
    }

    return $element;
}

1 Answer 1

0

I managed to get what I wanted inside theme_uc_attribute_add_to_cart by using:

foreach (element_children($form) as $aid) {
     foreach (element_children($form[$aid]) as $option) {

        $form[$aid][$option]['#prefix'] = '<div class="row single-double">';
        $form[$aid][$option]['#suffix'] = '</div>';

      }
    }

But I really don't want to mess with uc_attribute.theme.inc is there any other way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.