function authcache_commerce_form_commerce_cart_add_to_cart_form_alter in Authenticated User Page Caching (Authcache) 7.2
Implements hook_form_FORM_ID_alter().
Remove the uid value from the commerce add-to-cart form.
File
- modules/
authcache_commerce/ authcache_commerce.module, line 13 - Authcache support for Drupal Commerce.
Code
function authcache_commerce_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {
if (authcache_page_is_cacheable()) {
// Remove the customer uid #value in order to prevent it from entering the
// form cache. Instead add a validation callback which will restore the
// value from the $user global upon submission.
if (isset($form['uid']['#type']) && $form['uid']['#type'] === 'value' && !authcache_element_is_cacheable($form['uid'])) {
$form['uid']['#value'] = '';
$form['uid']['#element_validate'][] = 'authcache_commerce_form_restore_customer';
authcache_element_set_cacheable($form['uid']);
}
// The add-to-cart form maintains a list of value elements used to pass
// attribute state between form rebuilds.
if (isset($form['unchanged_attributes'])) {
foreach (element_children($form['unchanged_attributes']) as $key) {
if (isset($form['unchanged_attributes'][$key]['#type']) && $form['unchanged_attributes'][$key]['#type'] === 'value') {
authcache_element_set_cacheable($form['unchanged_attributes'][$key]);
}
}
}
}
}