You are here

webform_accordion.module in Webform Accordion 6

Same filename and directory in other branches
  1. 7.2 webform_accordion.module
  2. 7 webform_accordion.module

Main module file for the webform_accordion module.

File

webform_accordion.module
View source
<?php

/**
 * @file
 * Main module file for the webform_accordion module.
 */

/**
 * Implements hook_webform_component_info().
 */
function webform_accordion_webform_component_info() {
  $components = array();
  $components['accordion_grp'] = array(
    'label' => t('Accordion Container'),
    'description' => t('A container for grouping the tabs of an accordion.'),
    'features' => array(
      'csv' => FALSE,
      'default_value' => FALSE,
      'required' => FALSE,
      'conditional' => FALSE,
      'group' => TRUE,
      'title_inline' => FALSE,
    ),
    'file' => 'components/accordion_container.inc',
  );
  $components['accordion_tab'] = array(
    'label' => t('Accordion Tab'),
    'description' => t('A single tab in the accordion.  Must be placed inside of an Accordion Container.'),
    'features' => array(
      'csv' => FALSE,
      'default_value' => FALSE,
      'required' => FALSE,
      'conditional' => FALSE,
      'group' => TRUE,
      'title_inline' => FALSE,
    ),
    'file' => 'components/accordion_tab.inc',
  );
  return $components;
}

/**
 * Implements hook_theme().
 */
function webform_accordion_theme() {
  return array(
    'webform_accordion_container' => array(
      'arguments' => array(
        'id' => NULL,
        'content' => NULL,
        'element' => NULL,
      ),
      'path' => drupal_get_path('module', 'webform_accordion') . '/templates',
      'template' => 'webform-accordion-container',
    ),
    'webform_accordion_tab' => array(
      'arguments' => array(
        'title' => NULL,
        'content' => NULL,
        'element' => NULL,
      ),
      'path' => drupal_get_path('module', 'webform_accordion') . '/templates',
      'template' => 'webform-accordion-tab',
    ),
  );
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Adds configuration settings to the webform admin settings page.
 */
function webform_accordion_form_webform_admin_settings_alter(&$form, &$form_state) {
  $form['advanced']['webform_accordion'] = array(
    '#type' => 'radios',
    '#title' => t('Webform Accordion: Use default jQuery UI CSS?'),
    '#description' => t('Loads the default jQuery UI Library CSS for rendering the accordion.  Turn off to use your own css.'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#default_value' => variable_get('webform_accordion_use_jquery_ui_theme', 1),
  );
  $form['#submit'][] = 'webform_accordion_form_webform_admin_settings_submit';
  $jquery_ui_path = jquery_ui_get_path();
  $accordion_css_path = $jquery_ui_path . '/themes/base/ui.all.css';
  $path_exists = realpath($accordion_css_path);
  if ($path_exists === FALSE) {
    drupal_set_message(t('Webform Accordion: The jQuery UI library does not
      contain the default theme files.  The option of using the default CSS
      has been disabled.'), 'warning');
    $form['advanced']['webform_accordion']['#disabled'] = TRUE;
  }
}

/**
 * Submit callback for handling the additional admin settings on the
 * webform admin settings screen.
 */
function webform_accordion_form_webform_admin_settings_submit($form, &$form_state) {
  $value = $form_state['values']['webform_accordion'];
  variable_set('webform_accordion_use_jquery_ui_theme', $value);
}

/**
 * Helper function for embedding the module js and css files.
 */
function webform_accordion_insert_js_css() {
  static $embedded = FALSE;
  if (!$embedded) {
    jquery_ui_add(array(
      'ui.accordion',
    ));
    drupal_add_js(drupal_get_path('module', 'webform_accordion') . '/js/webform_accordion.js');
    if (variable_get('webform_accordion_use_jquery_ui_theme', TRUE)) {
      $jquery_ui_path = jquery_ui_get_path();
      $accordion_css_path = $jquery_ui_path . '/themes/base/';
      drupal_add_css($accordion_css_path . 'ui.all.css');
      drupal_add_css($accordion_css_path . 'jquery-ui.css');
      drupal_add_css($accordion_css_path . 'ui.accordion.css');
    }
    $embedded = TRUE;
  }
}

Functions

Namesort descending Description
webform_accordion_form_webform_admin_settings_alter Implements hook_form_FORM_ID_alter().
webform_accordion_form_webform_admin_settings_submit Submit callback for handling the additional admin settings on the webform admin settings screen.
webform_accordion_insert_js_css Helper function for embedding the module js and css files.
webform_accordion_theme Implements hook_theme().
webform_accordion_webform_component_info Implements hook_webform_component_info().