function formfilter_ui_form_alter in Formfilter 7
Implements hook_form_alter().
Add all users to select for assigning issues.
File
- formfilter_ui/
formfilter_ui.module, line 89 - Provide a UI for modification of the fields presented in any form in your installation without resorting to hook_form_alter() or a custom theme.
Code
function formfilter_ui_form_alter(&$form, &$form_state, $form_id) {
global $user;
$filters = variable_get('formfilter', array());
_formfilter_ui_add_node_filters($filters, $form, $form_id);
// If user has access to create form filters, add filtering link or filtering
// checkboxes.
if (variable_get('formfilter_ui', 1) && user_access('administer form filters')) {
// Comment form doesn't have a submit button and so can't be filtered
// if preview is required.
if ($form_id == 'comment_form' && variable_get('comment_preview', COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_REQUIRED) {
return;
}
if ($form_id == $_REQUEST['formfilter_id']) {
$form['formfilter'] = array(
'#type' => 'tree',
);
$form['#pre_render'][] = 'formfilter_ui_add_selectors';
$form['#formfilter_id'] = $form_id;
$form['#validate'][] = 'formfilter_ui_form_validate';
drupal_set_message(t('To register filters for this form, select which filters to apply and then submit the form normally.'));
}
else {
$form['#suffix'] .= '<div>' . l(t('Filter this form'), $_GET['q'], array(
'query' => array(
'formfilter_id' => $form_id,
),
)) . '</div>';
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$node = $form['#node'];
$form['#suffix'] .= '<div>' . l(t('Filter all node forms'), 'formfilter-ui/node', array(
'query' => array(
'formfilter_id' => 'formfilter_ui_node_form',
),
)) . '</div>';
}
// If the user applying a filter had permission to view forms without filtering,
// give her or him a link to preview the filtering if a filter exists on the form.
if (array_key_exists($form_id, $filters) && user_access('view forms without filtering') && !$_REQUEST['formfilter_preview']) {
$form['#suffix'] .= '<div>' . l(t('Preview a filtered version of this form'), $_GET['q'], array(
'query' => array(
'formfilter_preview' => '1',
),
)) . '</div>';
}
}
}
if (!$_REQUEST['formfilter_id'] && array_key_exists($form_id, $filters) && is_array($filters[$form_id]) && (!user_access('view forms without filtering') || $_REQUEST['formfilter_preview'])) {
$form['#pre_render'][] = 'formfilter_ui_pre_render';
}
// Simplify the node form.
if (variable_get('formfilter_simplify_node', 0) && isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
// Remove the most-used fields from the form admin fieldsets. Add them
// below the body.
if ($form['body_filter']) {
// Move 'promote' and 'sticky'.
if ($form['options']) {
foreach (array(
'promote',
'sticky',
) as $key) {
if ($form['options'][$key]) {
$form['body_filter'][$key] = $form['options'][$key];
unset($form['options'][$key]);
}
}
}
}
// Simplify the node form.
// Create an 'advanced' fieldset...
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => 'Advanced options',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// ...and move all first-level fieldsets there.
foreach (element_children($form) as $key) {
if (!in_array($key, array(
'advanced',
'taxonomy',
)) && $form[$key]['#type'] && $form[$key]['#type'] == 'fieldset') {
$form['advanced'][$key] = $form[$key];
unset($form[$key]);
}
}
// If nothing has been moved to the advanced fieldset, drop it.
if (!count(element_children($form['advanced']))) {
unset($form['advanced']);
}
}
}