You are here

function lightbox2_handler_field_lightbox2::render in Lightbox2 7.2

Same name and namespace in other branches
  1. 8 lightbox2_handler_field_lightbox2.inc \lightbox2_handler_field_lightbox2::render()
  2. 6 lightbox2_handler_field_lightbox2.inc \lightbox2_handler_field_lightbox2::render()
  3. 7 lightbox2_handler_field_lightbox2.inc \lightbox2_handler_field_lightbox2::render()

Render the trigger field and its linked popup information.

Overrides views_handler_field::render

File

./lightbox2_handler_field_lightbox2.inc, line 116
Contain the integration with views A handler to provide a field that is completely custom by the administrator.

Class

lightbox2_handler_field_lightbox2
@file Contain the integration with views A handler to provide a field that is completely custom by the administrator.

Code

function render($values) {

  // We need to have multiple unique IDs, one for each record.
  static $i = 0;
  static $link;
  if (!empty($this->options['trigger_field'])) {

    // We don't actually use the link, but we need it there for lightbox to function.
    if (empty($link)) {

      // Get the path name.
      $url = isset($_GET['q']) ? $_GET : '<front>';
      $path = '';
      $params = array();

      //Get the path and any parameters from the URL
      foreach ($url as $key => $value) {
        if ($key === 'q') {
          $path = $value;
        }
        else {
          $params[$key] = $value;
        }
      }
      $link = url($path, array(
        'absolute' => TRUE,
        'query' => $params,
      ));
    }

    // Get the token information and generate the value for the popup and the
    // caption.
    $tokens = $this
      ->get_render_tokens($this->options['alter']);
    $popup = filter_xss_admin($this->options['popup']);
    $caption = filter_xss_admin($this->options['caption']);
    $popup = strtr($popup, $tokens);
    $caption = strtr($caption, $tokens);
    $i++;

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