You are here

accordion_tab.inc in Webform Accordion 6

Same filename and directory in other branches
  1. 7.2 components/accordion_tab.inc
  2. 7 components/accordion_tab.inc

Defines the Accordion Tab webform component.

File

components/accordion_tab.inc
View source
<?php

/**
 * @file
 * Defines the Accordion Tab webform component.
 */

/**
 * Implements _webform_defaults_component().
 */
function _webform_defaults_accordion_tab() {
  return array(
    'name' => '',
    'form_key' => NULL,
    'pid' => 0,
    'weight' => 0,
    'extra' => array(
      'title_display' => 0,
      'description' => '',
      'private' => FALSE,
    ),
  );
}

/**
 * Implements _webform_edit_component().
 */
function _webform_edit_accordion_tab($component) {
  $form = array();
  return $form;
}

/**
 * Implements _webform_render_component().
 */
function _webform_render_accordion_tab($component, $value = NULL, $filter = TRUE) {
  $component['weight'] += 10;
  $class = 'webform-component-' . str_replace('_', '-', $component['type']) . ' accordion';
  $element = array(
    '#type' => $component['type'],
    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : NULL,
    '#weight' => $component['weight'],
    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
    '#attributes' => array(
      'class' => $class,
    ),
    '#pre_render' => array(
      'webform_element_title_display',
    ),
    '#webform_component' => $component,
    //id's are made unique in hook_form_alter
    '#id' => 'webform-component-' . str_replace('_', '-', $component['type']),
  );
  return $element;
}

/**
 * Pre-render function to set a accordion ID.
 */
function webform_accordion_tab_prerender($element) {
  $element['#attributes']['id'] = 'webform-component-' . str_replace('_', '-', implode('--', array_slice($element['#parents'], 1)));
  return $element;
}

/**
 * Implements _webform_display_component().
 */
function _webform_display_accordion_tab($component, $value, $format = 'html') {
  if ($format == 'text') {
    $element = array(
      '#title' => $component['name'],
      '#weight' => $component['weight'],
      '#post_render' => array(
        'webform_element_wrapper',
      ),
      '#theme_wrappers' => array(
        'webform_element_text',
      ),
      '#translatable' => array(
        'title',
      ),
    );
  }
  else {
    $element = _webform_render_accordion_tab($component, $value);
  }
  $element['#format'] = $format;
  return $element;
}

/**
 * Module specific instance of hook_theme().
 *
 * This allows each Webform component to add information into hook_theme().
 */
function _webform_theme_accordion_tab() {
  return array(
    'accordion_tab' => array(
      'arguments' => array(
        'element' => NULL,
      ),
      'file' => 'accordion_tab.inc',
      'path' => drupal_get_path('module', 'webform_accordion') . '/components',
    ),
  );
}

/**
 * Theme callback for rendering a single accordion tab.
 *
 * @param array $element
 *   The accordion tab element being rendered.
 *
 * @return string
 *   The HTML output for the tab.
 */
function theme_accordion_tab($element) {
  webform_accordion_insert_js_css();
  $title = $element['#title'] ? $element['#title'] : '';
  $content = !empty($element['#children']) ? $element['#children'] : '';
  return theme('webform_accordion_tab', $title, $content, $element);
}

Functions

Namesort descending Description
theme_accordion_tab Theme callback for rendering a single accordion tab.
webform_accordion_tab_prerender Pre-render function to set a accordion ID.
_webform_defaults_accordion_tab Implements _webform_defaults_component().
_webform_display_accordion_tab Implements _webform_display_component().
_webform_edit_accordion_tab Implements _webform_edit_component().
_webform_render_accordion_tab Implements _webform_render_component().
_webform_theme_accordion_tab Module specific instance of hook_theme().