/[drupal]/contributions/modules/lightbox2/lightbox2_handler_field_lightbox2.inc
ViewVC logotype

Diff of /contributions/modules/lightbox2/lightbox2_handler_field_lightbox2.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Sat Sep 5 09:52:26 2009 UTC revision 1.1.2.1, Sat Sep 5 09:52:26 2009 UTC
# Line 0  Line 1 
1    <?php
2    // $Id: $
3    
4    /**
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['rel_group'] = array('default' => TRUE);
20        $options['height'] = array('default' => '400px');
21        $options['width'] = array('default' => '600px');
22    
23        return $options;
24      }
25    
26      function options_form(&$form, &$form_state) {
27        parent::options_form($form, $form_state);
28    
29        $fields = array('trigger_field' => t('<None>'));
30        foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
31          // We only use fields up to this one.  Obviously we can't use this handler
32          // as the trigger handler.
33          if ($field == $this->options['id']) {
34            break;
35          }
36    
37          $fields[$field] = $handler->definition['title'];
38        }
39    
40        $form['trigger_field'] = array(
41          '#type' => 'select',
42          '#title' => t('Trigger field'),
43          '#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.'),
44          '#options' => $fields,
45          '#default_value' => $this->options['trigger_field'],
46          '#weight' => -10,
47        );
48    
49        $form['popup'] = array(
50          '#type' => 'textarea',
51          '#title' => t('Popup'),
52          '#description' => t('Combine tokens from the "Replacement patterns" below and html to create what the lightbox popup will become.'),
53          '#default_value' => $this->options['popup'],
54          '#weight' => -9,
55        );
56    
57        $form['rel_group'] = array(
58          '#type' => 'checkbox',
59          '#title' => t('Enable Lightbox grouping'),
60          '#default_value' => $this->options['rel_group'],
61          '#weight' => -8,
62        );
63    
64        $form['height'] = array(
65          '#type' => 'textfield',
66          '#title' => t('Height'),
67          '#description' => t('Specify the height of the lightbox2 popup window.  Because the content is dynamic, we cannot detect this value automatically.'),
68          '#default_value' => $this->options['height'],
69          '#weight' => -7,
70        );
71    
72        $form['width'] = array(
73          '#type' => 'textfield',
74          '#title' => t('Width'),
75          '#description' => t('Specify the width of the lightbox2 popup window.  Because the content is dynamic, we cannot detect this value automatically.'),
76          '#default_value' => $this->options['width'],
77          '#weight' => -6,
78        );
79    
80    
81    
82        // Remove the checkboxs and other irrelevant controls.
83        unset($form['alter']['alter_text']);
84        unset($form['alter']['make_link']);
85        unset($form['alter']['text']);
86        unset($form['alter']['path']);
87        unset($form['alter']['alt']);
88        unset($form['alter']['prefix']);
89        unset($form['alter']['suffix']);
90        unset($form['alter']['text']['#dependency']);
91        unset($form['alter']['text']['#process']);
92      }
93    
94      /**
95       * Render the trigger field and its linked popup information.
96       */
97      function render($values) {
98        // We need to have multiple unique IDs, one for each record.
99        static $i = 0;
100    
101        static $link;
102    
103        if (!empty($this->options['trigger_field'])) {
104    
105          // We don't actually use the link, but we need it there for lightbox to function.
106          if (empty($link)) {
107            //Get the path name.
108            $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
109            $link = url($path, array('absolute' => TRUE));
110          }
111    
112          //Get the token information and generate the value for the popup.
113          $tokens = $this->get_render_tokens();
114          $popup = filter_xss_admin($this->options['popup']);
115          $popup = strtr($popup, $tokens);
116    
117          $i++;
118    
119          // The outside div is there to hide all of the divs because if the specific lightbox
120          // div is hidden it won't show up as a lightbox.  We also specify a group
121          // in the rel attribute in order to link the whole View together for paging.
122          $group_name = ($this->options['rel_group'] ?  'lightbox-popup-{$this->view->name}' : '');
123          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') . "]'>". $tokens["[{$this->options['trigger_field']}]"] ."</a>
124                    <div style='display: none;'><div id='lightbox-popup-{$i}' class='lightbox-popup'>$popup</div></div>";
125        }
126        else {
127          return;
128        }
129      }
130    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2