'admin/settings/checkall', 'title' => t('Checkall boxes'), 'callback' => 'checkall_settings', 'access' => user_access('administer site configuration'), 'description' => t('Add check all checkboxes to site forms.'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } /** * Implementation of hook_help() */ function checkall_help($section) { switch ($section) { case 'admin/modules#description': return t("Enables you to active a Check All box for your site's forms."); } } /** * Implementation of hook_form_alter() * * Automatically adds checkboxes to forms for fields the admin specifies. */ function checkall_form_alter($form_id, &$form) { // $checkall_forms = variable_get('checkall_forms', array('comment_admin_overview' => array(array('id' => 'comments', 'weight' => -1)))); $checkall_forms = variable_get('checkall_forms', array()); if (in_array($form_id, array_keys($checkall_forms))) { foreach ($checkall_forms[$form_id] as $field) { $form['options']['checkall-'. $column] = array('#title' => t('Check All') .' ', '#type' => 'checkbox_check_all', '#value' => $field['id'], '#weight' => $field['weight']); } } } /******************************************************************************* * Callback Functions and Forms ******************************************************************************/ function checkall_settings() { $output = t('Enable "Check All" boxes on the following forms:') . drupal_get_form('checkall_admin_form'); return $output; } function checkall_admin_form() { $enabled = variable_get('checkall_forms', array()); foreach ($enabled as $key => $value) { switch ($key) { case 'comment_admin_overview': $defaults[] = 'comments'; break; case 'node_admin_nodes': $defaults[] = 'posts'; break; case 'user_admin_account': $defaults[] = 'users'; break; } } $form['site_forms'] = array( '#type' => 'checkboxes', '#default_value' => $defaults, '#options' => array( 'comments' => t('Comment forms'), 'posts' => t('Post form'), 'users' => t('Users form'), ) ); $form['checkall'] = array( '#type' => 'checkbox_check_all', '#title' => t('Select all'), '#value' => 'site_forms', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); return $form; } function checkall_admin_form_submit($form_id, $form_values) { foreach ($form_values['site_forms'] as $key => $value) { if ($key === $value) { switch ($key) { case 'comments': $settings['comment_admin_overview'] = array(array('id' => 'comments', 'weight' => -1)); break; case 'posts': $settings['node_admin_nodes'] = array(array('id' => 'nodes', 'weight' => -1)); break; case 'users': $settings['user_admin_account'] = array(array('id' => 'accounts', 'weight' => -1)); break; } } } variable_set('checkall_forms', $settings); drupal_set_message(t('Checkall settings saved.')); } /******************************************************************************* * Module and Helper Functions ******************************************************************************/ /** * Format a 'check all / check none' checkbox. * * @param $element * An associative array containing the properties of the element. * @return * A themed HTML string representing the container for the checkbox. * The checkbox is added dynamically with Javascript. */ function theme_checkbox_check_all($element) { drupal_add_js(drupal_get_path('module', 'checkall') .'/checkall.js'); if (is_array($element['#value'])) { $id = $element['#value']['#id']; } else { $id = 'edit-'. $element['#value']; } $label = ''; $placeholder = '-- '; return '
' . $placeholder . $label . '
'; }