function authcache_p13n_process_config in Authenticated User Page Caching (Authcache) 7.2
Form API process callback for config element.
Related topics
1 string reference to 'authcache_p13n_process_config'
- authcache_p13n_element_info in modules/
authcache_p13n/ authcache_p13n.module - Implements hook_element_info().
File
- modules/
authcache_p13n/ authcache_p13n.module, line 1333 - Provides methods for serving personalized content fragments.
Code
function authcache_p13n_process_config($element, &$form_state) {
// Prepare #default_value
$defaults = authcache_p13n_config_defaults();
if (empty($element['#default_value'])) {
$element['#default_value'] = $defaults;
}
else {
$element['#default_value'] = $element['#default_value'] + $defaults;
}
$element['#tree'] = TRUE;
$element['#attached']['js'][] = drupal_get_path('module', 'authcache_p13n') . '/authcache_p13n.admin.js';
$element['#attached']['css'][] = drupal_get_path('module', 'authcache_p13n') . '/authcache_p13n.admin.css';
$enabled_id = drupal_html_id($element['#id'] . '-status');
$element['status'] = array(
'#type' => 'checkbox',
'#title' => t('Authcache'),
'#description' => t('Use ESI or Ajax to deliver this content.'),
'#default_value' => $element['#default_value']['status'],
'#id' => $enabled_id,
);
$container_id = drupal_html_id($element['#id'] . '-container');
$element['settings'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'authcache-p13n-config-settings-wrapper',
),
),
'#parents' => $element['#parents'],
'#id' => $container_id,
'#states' => array(
'visible' => array(
'#' . $enabled_id => array(
'checked' => TRUE,
),
),
),
);
$element['settings']['lifespan'] = array(
'#type' => 'authcache_duration_select',
'#title' => t('Cache lifetime'),
'#description' => t('The maximum time an external cache or the browser can keep a copy of this content.'),
'#durations' => array(
0,
60,
300,
1800,
3600,
21600,
518400,
),
'#default_value' => $element['#default_value']['lifespan'],
'#zero_duration' => t('Never cache'),
);
$element['settings']['peruser'] = array(
'#type' => 'checkbox',
'#title' => t('Per user'),
'#description' => t('Select when content is different depending on user.'),
'#default_value' => $element['#default_value']['peruser'],
);
$element['settings']['perpage'] = array(
'#type' => 'checkbox',
'#title' => t('Per page'),
'#description' => t('Select when content is different depending on the URL of the page.'),
'#default_value' => $element['#default_value']['perpage'],
);
// Clients.
$parents_for_clients = array_merge($element['#parents'], array(
'clients',
));
$client_info = authcache_p13n_client_info();
$clients = $element['#default_value']['clients'];
$element['settings']['#clients'] = $clients;
// Status.
$client_status_id = drupal_html_id($element['#id'] . '-clients-status-wrapper');
$element['settings']['clients']['status'] = array(
'#type' => 'item',
'#title' => t('Enabled clients'),
'#prefix' => '<div ' . drupal_attributes(array(
'id' => $client_status_id,
'class' => 'clients-status-wrapper',
)) . '>',
'#suffix' => '</div>',
'#description' => t('Select the method(s) used to substitute personalized markup.'),
);
$element['settings']['clients']['status']['status-warning'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'authcache-p13n-clients-warning',
'messages',
'warning',
),
),
'message' => array(
'#markup' => count($client_info) > 0 ? t('Please select at least one client, otherwise markup substitution will not work.') : t('No client module enabled, markup substitution will not work.'),
),
);
$enabled_clients = 0;
foreach ($client_info as $name => $client) {
$status = !isset($clients[$name]['status']) || !empty($clients[$name]['status']);
$element['settings']['clients']['status'][$name] = array(
'#type' => 'checkbox',
'#title' => $client['title'],
'#default_value' => $status,
'#parents' => array_merge($parents_for_clients, array(
$name,
'status',
)),
);
if ($status) {
$enabled_clients++;
}
}
if ($enabled_clients) {
$element['settings']['clients']['status']['status-warning']['#attributes']['class'][] = 'element-hidden';
}
// Client order (tabledrag).
$client_order_wrapper_id = drupal_html_id($element['#id'] . '-clients-order-wrapper');
$client_order_tabledrag_id = drupal_html_id($element['#id'] . '-clients-order-table');
$element['settings']['clients']['order'] = array(
'#type' => 'item',
'#title' => t('Client order'),
'#theme' => 'authcache_p13n_config_client_order',
'#id' => $client_order_wrapper_id,
'#tabledrag_id' => $client_order_tabledrag_id,
'#description' => t('Set client precedence by moving preferred client modules to the top. If more than one client module is capable of handling markup substitution the one ranking the highest is used.'),
);
foreach ($client_info as $name => $client) {
$weight = empty($clients[$name]['weight']) ? 0 : $clients[$name]['weight'];
$element['settings']['clients']['order'][$name]['client'] = array(
'#markup' => $client['title'],
);
$element['settings']['clients']['order'][$name]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight for @title', array(
'@title' => $client['title'],
)),
'#title_display' => 'invisible',
'#delta' => 50,
'#default_value' => $weight,
'#parents' => array_merge($parents_for_clients, array(
$name,
'weight',
)),
);
$element['settings']['clients']['order'][$name]['#weight'] = $weight;
}
$element['settings']['fallback'] = array(
'#type' => 'radios',
'#title' => t('Fallback'),
'#description' => t('What to do when no client is available (neither ESI nor Ajax).'),
'#options' => array(
'cancel' => t('Cancel caching'),
'hide' => t('Hide content'),
),
'#default_value' => $element['#default_value']['fallback'],
);
return $element;
}