function authcache_form_alter in Authenticated User Page Caching (Authcache) 7.2
Same name and namespace in other branches
- 6 authcache.module \authcache_form_alter()
- 7 authcache.module \authcache_form_alter()
Implements hook_form_alter().
Related topics
File
- ./
authcache.module, line 211 - Authenticated User Page Caching (and anonymous users, too!)
Code
function authcache_form_alter(&$form, &$form_state, $form_id) {
global $user;
if (authcache_page_is_cacheable()) {
// Ensure that the default form_after build callback is called first.
if (empty($form['#after_build'])) {
$form['#after_build'] = array(
'_authcache_default_form_after_build',
);
}
else {
array_unshift($form['#after_build'], '_authcache_default_form_after_build');
}
// Add post-render callback ensuring that caching is canceled when a form
// requiring the form cache is rendered on a page for authenticated users.
if ($user->uid && !empty($form['form_build_id'])) {
authcache_element_suspect($form['form_build_id'], t('Form requiring the form cache on the page. Enable authcache_form or implement custom code capable of handling cached forms.'));
}
// Add post-render callback ensuring that caching is canceled when a form
// was not handled by any module.
if (!empty($form['form_token'])) {
authcache_element_suspect($form['form_token'], t('Form with CSRF protection on page. Enable authcache_form or implement custom code capable of handling CSRF protected forms.'));
}
// Recursively find elements of type value and flag them as suspicous.
authcache_form_value_suspect($form, $form_id);
}
// Alter all forms.
switch ($form_id) {
case 'user_profile_form':
// Don't allow user local timezone.
if (authcache_account_allows_caching()) {
unset($form['timezone']);
}
break;
case 'contact_site_form':
case 'contact_personal_form':
if ($user->uid && authcache_page_is_cacheable()) {
unset($form['name']['#default_value']);
unset($form['mail']['#default_value']);
}
break;
}
}