Projet

Général

Profil

Paste
Télécharger (5,8 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / lightbox2 / lightbox2_handler_field_lightbox2.inc @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * Contain the integration with views
5
 * A handler to provide a field that is completely custom by the administrator.
6
 *
7
 * @ingroup views_field_handlers
8
 */
9
class lightbox2_handler_field_lightbox2 extends views_handler_field {
10
  function query() {
11
    // Do nothing, as this handler does not need to do anything to the query itself.
12
  }
13

    
14
  function option_definition() {
15
    $options = parent::option_definition();
16

    
17
    $options['trigger_field'] = array('default' => '');
18
    $options['popup'] = array('default' => '');
19
    $options['caption'] = array('default' => '');
20
    $options['rel_group'] = array('default' => TRUE);
21
    $options['custom_group'] = array('default' => '');
22
    $options['height'] = array('default' => '400px');
23
    $options['width'] = array('default' => '600px');
24

    
25
    return $options;
26
  }
27

    
28
  function options_form(&$form, &$form_state) {
29
    parent::options_form($form, $form_state);
30

    
31
    $fields = array('trigger_field' => t('<None>'));
32
    foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
33
      // We only use fields up to this one.  Obviously we can't use this handler
34
      // as the trigger handler.
35
      if ($field == $this->options['id']) {
36
        break;
37
      }
38

    
39
      $fields[$field] = $handler->definition['title'];
40
    }
41

    
42
    $form['trigger_field'] = array(
43
      '#type' => 'select',
44
      '#title' => t('Trigger field'),
45
      '#description' => t('Select the field that should be turned into the trigger for the lightbox.  Only fields that appear before this one in the field list may be used.'),
46
      '#options' => $fields,
47
      '#default_value' => $this->options['trigger_field'],
48
      '#weight' => -12,
49
    );
50

    
51
    $form['popup'] = array(
52
      '#type' => 'textarea',
53
      '#title' => t('Popup'),
54
      '#description' => t('Combine tokens from the "Replacement patterns" below and html to create what the lightbox popup will become.'),
55
      '#default_value' => $this->options['popup'],
56
      '#weight' => -11,
57
    );
58

    
59
    $form['caption'] = array(
60
      '#type' => 'textfield',
61
      '#title' => t('Caption'),
62
      '#description' => t('Combine tokens from the "Replacement patterns" below and html to create the caption shown under the lightbox. Leave empty for no caption.'),
63
      '#default_value' => $this->options['caption'],
64
      '#weight' => -10,
65
    );
66

    
67
    $form['rel_group'] = array(
68
      '#type' => 'checkbox',
69
      '#title' => t('Automatic generated Lightbox group'),
70
      '#description' => t('Enable Lightbox grouping using a generated group name for this view.'),
71
      '#default_value' => $this->options['rel_group'],
72
      '#weight' => -9,
73
    );
74

    
75
    $form['custom_group'] = array(
76
      '#type' => 'textfield',
77
      '#title' => t('Custom Lightbox group'),
78
      '#description' => t('Enable Lightbox grouping with a given string as group. Overrides the automatically generated group name above.'),
79
      '#default_value' => $this->options['custom_group'],
80
      '#weight' => -8,
81
    );
82

    
83
    $form['height'] = array(
84
      '#type' => 'textfield',
85
      '#title' => t('Height'),
86
      '#description' => t('Specify the height of the lightbox2 popup window.  Because the content is dynamic, we cannot detect this value automatically.'),
87
      '#default_value' => $this->options['height'],
88
      '#weight' => -7,
89
    );
90

    
91
    $form['width'] = array(
92
      '#type' => 'textfield',
93
      '#title' => t('Width'),
94
      '#description' => t('Specify the width of the lightbox2 popup window.  Because the content is dynamic, we cannot detect this value automatically.'),
95
      '#default_value' => $this->options['width'],
96
      '#weight' => -6,
97
    );
98

    
99

    
100

    
101
    // Remove the checkboxs and other irrelevant controls.
102
    unset($form['alter']['alter_text']);
103
    unset($form['alter']['make_link']);
104
    unset($form['alter']['text']);
105
    unset($form['alter']['path']);
106
    unset($form['alter']['alt']);
107
    unset($form['alter']['prefix']);
108
    unset($form['alter']['suffix']);
109
    unset($form['alter']['text']['#dependency']);
110
    unset($form['alter']['text']['#process']);
111
  }
112

    
113
  /**
114
   * Render the trigger field and its linked popup information.
115
   */
116
  function render($values) {
117
    // We need to have multiple unique IDs, one for each record.
118
    static $i = 0;
119

    
120
    static $link;
121

    
122
    if (!empty($this->options['trigger_field'])) {
123

    
124
      // We don't actually use the link, but we need it there for lightbox to function.
125
      if (empty($link)) {
126
        // Get the path name.
127
        $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
128
        $link = url($path, array('absolute' => TRUE));
129
      }
130

    
131
      // Get the token information and generate the value for the popup and the
132
      // caption.
133
      $tokens = $this->get_render_tokens($this->options['alter']);
134
      $popup = filter_xss_admin($this->options['popup']);
135
      $caption = filter_xss_admin($this->options['caption']);
136
      $popup = strtr($popup, $tokens);
137
      $caption = strtr($caption, $tokens);
138

    
139
      $i++;
140

    
141
      // The outside div is there to hide all of the divs because if the specific lightbox
142
      // div is hidden it won't show up as a lightbox.  We also specify a group
143
      // in the rel attribute in order to link the whole View together for paging.
144
      $group_name = !empty($this->options['custom_group']) ? $this->options['custom_group'] : ($this->options['rel_group'] ? 'lightbox-popup-' . $this->view->name . '-' . implode('/', $this->view->args) : '');
145
      return "<a href='$link #lightbox-popup-{$i}'  rel='lightmodal[{$group_name}|width:" . ($this->options['width'] ? $this->options['width'] : '600px') . ';height:' . ($this->options['height'] ? $this->options['height'] : '600px') . "][" . $caption . "]'>" . $tokens["[{$this->options['trigger_field']}]"] . "</a>
146
                <div style='display: none;'><div id='lightbox-popup-{$i}' class='lightbox-popup'>$popup</div></div>";
147
    }
148
    else {
149
      return;
150
    }
151
  }
152
}