function _authcache_form_after_build in Authenticated User Page Caching (Authcache) 7.2
Form after_build callback for forms on cacheable pages.
Setup form such that the per-session form token (used for CSRF protection) can be retrieved separately.
See also
1 string reference to '_authcache_form_after_build'
- authcache_form_form_alter in modules/
authcache_form/ authcache_form.module - Implements hook_form_alter().
File
- modules/
authcache_form/ authcache_form.module, line 163 - Form token retrieval for Authcache.
Code
function _authcache_form_after_build($form, $form_state) {
global $user;
if (authcache_page_is_cacheable()) {
if (!empty($form['form_build_id']) && $user->uid && !authcache_element_is_cacheable($form['form_build_id'])) {
// Cached forms break for authenticated users unless Cache Object API is
// configured properly.
if (module_exists('cacheobject')) {
authcache_element_set_cacheable($form['form_build_id']);
}
else {
authcache_cancel(t('Cached form on the page (likely Ajax enabled). Download and configure the Cache Object API module.'));
}
}
if (!empty($form['form_token']) && !authcache_element_is_cacheable($form['form_token'])) {
// Replace hidden form_token input with personalization request fragment.
$form_token_id = isset($form['#token']) ? $form['#token'] : $form['#form_id'];
authcache_p13n_attach($form['form_token'], array(
'#theme' => 'authcache_p13n_fragment',
'#fragment' => 'form-token',
'#param' => $form_token_id,
'#fallback' => 'cancel',
));
authcache_element_set_cacheable($form['form_token']);
}
}
return $form;
}