You are here

function authcache_ubercart_form_alter in Authenticated User Page Caching (Authcache) 7.2

Implements hook_form_alter().

@todo: Remove when https://www.drupal.org/node/2885388 is resolved.

File

modules/authcache_ubercart/authcache_ubercart.module, line 47
Authcache support for Ubercart.

Code

function authcache_ubercart_form_alter(&$form, &$form_state) {
  if (isset($form_state['build_info']['base_form_id']) && $form_state['build_info']['base_form_id'] === 'uc_product_add_to_cart_form') {

    // The Ubercart Attributes module adds a form element 'attributes' => NULL
    // in the add-to-cart form for products which do not have any product
    // attributes. Authcache Form chockes on that, so let's just remove it.
    // @see https://www.drupal.org/node/2885086
    // @see uc_attribute_uc_form_alter()
    if (isset($form['products']) || isset($form['sub_products'])) {
      if (isset($form['products'])) {
        $element =& $form['products'];
      }
      else {
        $element =& $form['sub_products'];
      }
      foreach (element_children($element) as $key) {
        if (empty($element['attributes'])) {
          unset($element['attributes']);
        }
      }
    }
    elseif (empty($form['attributes'])) {
      unset($form['attributes']);
    }
  }
}