You are here

accordion_blocks.module in Accordion Blocks 6

File

accordion_blocks.module
View source
<?php

/*
 *@file 
 * This module privide the accordion widget for the blocks on left and right side
 */

/*
 * Implementation of hook_init()
 */
function accordion_blocks_init() {

  // including accordion related javascript and css files
  jquery_ui_add('ui.accordion');
  drupal_add_js(drupal_get_path('module', 'accordion_blocks') . '/accordion_init.js');
  drupal_add_css(drupal_get_path('module', 'accordion_blocks') . '/accordion_init.css');
}
function accordion_blocks_theme_registry_alter(&$theme_registry) {
  $theme_registry['block']['theme paths'][] = drupal_get_path('module', 'accordion_blocks');
}
function accordion_blocks_preprocess_block(&$vars) {
  $regions_list = variable_get('accordion_regions', array(
    'left' => 'left',
    'right' => 'right',
  ));
  $active_regions = array();
  foreach ($regions_list as $region => $value) {
    if (trim($region) == trim($value)) {
      $active_regions[] = $region;
    }
  }
  if (in_array($vars['block']->region, $active_regions)) {
    $vars['template_files'] = array(
      'block',
    );
  }
}

/**
 * Implementation of template_preprocess_page()
 */
function accordion_blocks_preprocess_page(&$variables) {

  // to add the accordian effect add this parent div for the blocks
  $regions_list = variable_get('accordion_regions', array(
    'left' => 'left',
    'right' => 'right',
  ));
  foreach ($regions_list as $region => $is_enabled) {
    if (!empty($variables[$region]) && $is_enabled) {
      $variables[$region] = '<div class="accordion_blocks_container">' . $variables[$region] . '</div>';
    }
  }
}
function accordion_blocks_menu() {

  //settings page
  $items['admin/settings/accordion_blocks'] = array(
    "title" => t("Accordion Blocks"),
    "description" => t("Configure the Regions to apply Accordion effect."),
    "page callback" => "drupal_get_form",
    "page arguments" => array(
      'accordion_blocks_settings_form',
    ),
    "access arguments" => array(
      'administer site configuration',
    ),
  );
  return $items;
}
function accordion_blocks_settings_form() {
  $form = array();
  global $user;
  $themes = list_themes();
  $theme = !empty($user->theme) && !empty($themes[$user->theme]->status) ? $user->theme : variable_get('theme_default', 'garland');
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
  $regions_list = system_region_list($theme);
  $form['accordion_regions'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select Regions to apply Accordion effect'),
    '#options' => $regions_list,
    '#default_value' => variable_get('accordion_regions', array(
      'left' => 'left',
      'right' => 'right',
    )),
  );
  return system_settings_form($form);
}