array( 'blocks' => array_change_key_case(variable_get('collapsiblock_settings', array()), CASE_LOWER), 'default_state' => variable_get('collapsiblock_default_state', 1), 'slide_type' => variable_get('collapsiblock_slide_type', 1), 'slide_speed' => variable_get('collapsiblock_slide_speed', 200), 'block_title' => $theme_settings['collapsiblock_title'], 'block' => $theme_settings['collapsiblock_block'], 'block_content' => $theme_settings['collapsiblock_content'], )), array('type' => 'setting' , 'scope' => JS_DEFAULT)); } /** * Implements hook_menu(). */ function collapsiblock_menu() { $items = array(); $items['admin/config/user-interface/collapsiblock'] = array( 'title' => 'Collapsiblock', 'description' => 'Configuration for collapsible blocks', 'page callback' => 'drupal_get_form', 'page arguments' => array('collapsiblock_admin_settings'), 'access arguments' => array('administer site configuration'), ); return $items; } /** * Admin settings. */ function collapsiblock_admin_settings($form, &$form_state) { $form = array(); $form['collapsiblock_default_state'] = array( '#type' => 'radios', '#title' => t('Default block collapse behavior'), '#options' => array(1 => t('None.'), 2 => t('Collapsible, expanded by default.'), 3 => t('Collapsible, collapsed by default.'), 4 => t('Collapsible, collapsed all the time.')), '#default_value' => variable_get('collapsiblock_default_state', 1), ); $form['collapsiblock_slide_type'] = array( '#type' => 'radios', '#title' => t('Default animation type'), '#options' => array(1 => t('Slide'), 2 => t('Fade and slide')), '#description' => t('Slide is the Drupal default while Fade and slide adds a nice fade effect.'), '#default_value' => variable_get('collapsiblock_slide_type', 1), ); $form['collapsiblock_slide_speed'] = array( '#type' => 'select', '#title' => t('Animation speed'), '#options' => drupal_map_assoc(array('50', '100', '200', '300', '400', '500', '700', '1000', '1300')), '#description' => t('The animation speed in milliseconds.'), '#default_value' => variable_get('collapsiblock_slide_speed', 200), ); $form['collapsiblock_help'] = array( '#markup' => t('If collapsiblock doesn\'t work out of the box, you can force CSS selectors on appearance settings.', array('!url' => url('admin/appearance/settings'))), ); $form = system_settings_form($form); return $form; } /** * Default theme's settings */ function collapsiblock_default_settings() { $defaults = array( 'collapsiblock_block' => 'div.block', 'collapsiblock_content' => 'div.content', 'collapsiblock_title' => ':header:first', ); return $defaults; } /** * Implements hook_form_alter(). */ function collapsiblock_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'system_theme_settings') { $settings = variable_get($form['var']['#value'], array()); $settings = array_merge(collapsiblock_default_settings(), $settings, array()); $form['collapsiblock'] = array( '#type' => 'fieldset', '#title' => t('Collapsiblock selectors'), '#description' => t("Force CSS selector if collapsiblock doesn't work out of the box"), '#weight' => 0, '#attributes' => array('id' => 'collapsiblock_form'), ); $form['collapsiblock']['collapsiblock_block'] = array( '#type' => 'textfield', '#title' => t('Block'), '#default_value' => $settings['collapsiblock_block'], ); $form['collapsiblock']['collapsiblock_title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $settings['collapsiblock_title'], ); $form['collapsiblock']['collapsiblock_content'] = array( '#type' => 'textfield', '#title' => t('Block content'), '#default_value' => $settings['collapsiblock_content'], ); } if ($form_id == 'block_admin_configure') { $settings = variable_get('collapsiblock_settings', array()); $form['#submit'][] = 'collapsiblock_submit'; $form['collapsiblock'] = array( '#type' => 'fieldset', '#title' => t('Collapsible'), '#collapsible' => TRUE, '#weight' => -5 ); $block_id = 'block-' . str_replace('_', '-', $form['module']['#value']) . '-' . drupal_strtolower(str_replace('_', '-', $form['delta']['#value'])); if (isset($settings[$block_id])) { $default_value = $settings[$block_id] ? $settings[$block_id] : variable_get('collapsiblock_default_state', 1); } else { $default_value = 1; } $form['collapsiblock']['collapse_type'] = array( '#type' => 'radios', '#title' => t('Block collapse behavior'), '#options' => array(1 => t('None.'), 2 => t('Collapsible, expanded by default.'), 3 => t('Collapsible, collapsed by default.'), 4 => t('Collapsible, collapsed all the time.')), '#default_value' => $default_value, ); } } /** * Form submission handler for block_admin_configure(). * * @see block_admin_configure() * @see collapsiblock_form_alter() */ function collapsiblock_submit($form, &$form_state) { $settings = variable_get('collapsiblock_settings', array()); $settings['block-' . str_replace('_', '-', $form_state['values']['module']) . '-' . drupal_strtolower(str_replace('_', '-', $form_state['values']['delta']))] = $form_state['values']['collapse_type']; variable_set('collapsiblock_settings', $settings); }