Projet

Général

Profil

Paste
Télécharger (3,05 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / components / fieldset.inc @ 8d02775b

1
<?php
2

    
3
/**
4
 * @file
5
 * Webform module fieldset component.
6
 */
7

    
8
/**
9
 * Implements _webform_defaults_component().
10
 */
11
function _webform_defaults_fieldset() {
12
  return array(
13
    'name' => '',
14
    'form_key' => NULL,
15
    'pid' => 0,
16
    'weight' => 0,
17
    'extra' => array(
18
      'title_display' => 0,
19
      'collapsible' => 0,
20
      'collapsed' => 0,
21
      'description' => '',
22
      'description_above' => FALSE,
23
      'private' => FALSE,
24
    ),
25
  );
26
}
27

    
28
/**
29
 * Implements _webform_edit_component().
30
 */
31
function _webform_edit_fieldset($component) {
32
  $form = array();
33
  $form['display']['collapsible'] = array(
34
    '#type' => 'checkbox',
35
    '#title' => t('Collapsible'),
36
    '#default_value' => $component['extra']['collapsible'],
37
    '#description' => t('If this fieldset is collapsible, the user may open or close the fieldset.'),
38
    '#weight' => 0,
39
    '#parents' => array('extra', 'collapsible'),
40
  );
41
  $form['display']['collapsed'] = array(
42
    '#type' => 'checkbox',
43
    '#title' => t('Collapsed by Default'),
44
    '#default_value' => $component['extra']['collapsed'],
45
    '#description' => t('Collapsible fieldsets are "open" by default. Select this option to default the fieldset to "closed."'),
46
    '#weight' => 3,
47
    '#parents' => array('extra', 'collapsed'),
48
  );
49
  return $form;
50
}
51

    
52
/**
53
 * Implements _webform_render_component().
54
 */
55
function _webform_render_fieldset($component, $value = NULL, $filter = TRUE, $submission = NULL) {
56
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
57

    
58
  $element = array(
59
    '#type' => 'fieldset',
60
    '#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
61
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : NULL,
62
    '#weight' => $component['weight'],
63
    '#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
64
    '#collapsible' => $component['extra']['collapsible'],
65
    '#collapsed' => $component['extra']['collapsed'],
66
    '#attributes' => array('class' => array('webform-component-fieldset')),
67
    '#pre_render' => array('webform_fieldset_prerender', 'webform_element_title_display'),
68
    '#translatable' => array('title', 'description'),
69
  );
70

    
71
  return $element;
72
}
73

    
74
/**
75
 * Pre-render function to set a unique fieldset class name.
76
 */
77
function webform_fieldset_prerender($element) {
78
  $element['#id'] = NULL;
79
  $element['#attributes']['class'][] = 'webform-component--' . str_replace('_', '-', implode('--', array_slice($element['#parents'], 1)));
80
  return $element;
81
}
82

    
83
/**
84
 * Implements _webform_display_component().
85
 */
86
function _webform_display_fieldset($component, $value, $format = 'html', $submission = array()) {
87
  if ($format == 'text') {
88
    $element = array(
89
      '#title' => $component['name'],
90
      '#weight' => $component['weight'],
91
      '#theme_wrappers' => array('webform_element_text'),
92
      '#translatable' => array('title'),
93
    );
94
  }
95
  else {
96
    $element = _webform_render_fieldset($component, $value);
97
  }
98

    
99
  $element['#format'] = $format;
100

    
101
  return $element;
102
}