function flag_lists_form_alter in Flag Lists 7
Same name and namespace in other branches
- 8 flag_lists.module \flag_lists_form_alter()
- 6 flag_lists.module \flag_lists_form_alter()
- 7.3 flag_lists.module \flag_lists_form_alter()
- 4.0.x flag_lists.module \flag_lists_form_alter()
Implementation of hook_form_alter().
File
- ./
flag_lists.module, line 279 - The Flag Lists module.
Code
function flag_lists_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'flag_form':
// A template flag should always have a record in the flag_lists_types table.
$result = db_select('flag_lists_types', 'f')
->fields('f')
->execute();
foreach ($result as $type) {
$types[$type->name] = $type->type;
}
if (isset($types[$form['name']['#default_value']])) {
$form['name']['#type'] = 'value';
$form['global']['#type'] = 'value';
$form['title']['#description'] = t('A short, descriptive title for this template. It will be used in administrative interfaces to refer to this template.');
// Warn about types that already have a template.
foreach ($form['access']['types']['#options'] as $option => $value) {
if (in_array($option, $types) && $form['access']['types']['#default_value'] != $option) {
$form['access']['types']['#options'][$option] .= '<span class="description">' . t('(Already has a template.)') . '</span>';
}
}
$form['access']['types']['#description'] .= t('A type may only be selected in one list template.');
// Unset anon permissions for now. @todo allow anon listing.
unset($form['access']['roles']['flag']['#options'][1]);
unset($form['access']['roles']['unflag']['#options'][1]);
foreach (element_children($form['display']) as $display) {
$form['display'][$display]['#type'] = 'value';
}
$form['display']['link_type']['#default_value'] = 'fl_template';
$form['display']['#description'] = t('Unlike normal flags, lists are only displayed in a block provided by this module or in views blocks. See <a href="/admin/build/block/list">the block admin page</a> to place the block.');
$form['#validate'][] = 'flag_lists_template_validate';
$form['#submit'][] = 'flag_lists_template_submit';
}
break;
case 'views_exposed_form':
// Force the exposed filters to perform actions on the page itself because
// the views default viwe didn't come with a page display
if ($form['#id'] == 'views-exposed-form-flag-lists-default') {
$form['#action'] = '/' . implode('/', arg());
}
break;
}
// Flag lists operations related changes
if (strpos($form_id, 'views_form_') === 0) {
$flo = _flag_lists_ops_get_field($form_state['build_info']['args'][0]);
// Not a FLO-enabled views form.
if (empty($flo)) {
return;
}
// Add FLO's custom callbacks.
$form['#validate'][] = 'flag_lists_ops_form_validate';
$form['#submit'][] = 'flag_lists_ops_form_submit';
// Allow FLO to work when embedded using views_embed_view(), or in a block.
if (empty($flo->view->override_path)) {
if (!empty($flo->view->preview) || $flo->view->display_handler instanceof views_plugin_display_block) {
$flo->view->override_path = $_GET['q'];
}
}
// Quickfix for FLO & exposed filters using ajax. See http://drupal.org/node/1191928.
$query = drupal_get_query_parameters($_GET, array(
'q',
));
$form['#action'] = url($flo->view
->get_url(), array(
'query' => $query,
));
// Add basic FLO functionality.
if ($form_state['step'] == 'views_form_views_form') {
$form = flag_lists_ops_form($form, $form_state, $flo);
}
}
}