You are here

function imagepicker_colorbox_handler_field_colorbox::render in Image Picker 7

File

handlers/imagepicker_colorbox_handler_field_colorbox.inc, line 62
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL class inherited from handler for Colorbox module.

Class

imagepicker_colorbox_handler_field_colorbox
A handler to provide a field that is completely customizable by the administrator.

Code

function render($values) {

  // We need to have multiple unique IDs, one for each record.
  static $i = 0;
  $i++;

  // Return nothing if no trigger filed is selected.
  if (empty($this->options['trigger_field'])) {
    return;
  }

  // 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);
  $width = $this->options['width'] ? $this->options['width'] : '600px';
  $height = $this->options['height'] ? $this->options['height'] : '400px';
  $gallery_id = !empty($this->options['custom_gid']) ? $this->options['custom_gid'] : ($this->options['gid'] ? 'gallery-' . $this->view->name : '');
  $link_text = $tokens["[{$this->options['trigger_field']}]"];
  $hide = $this->options['hide'];
  $link_options = array(
    'html' => TRUE,
    'fragment' => 'colorbox-inline-' . $i,
    'query' => array(
      'width' => $width,
      'height' => $height,
      'title' => $caption,
      'inline' => 'true',
    ),
    'attributes' => array(
      'class' => 'colorbox-inline' . ($hide && $i > $hide ? ' js-hide' : ''),
      'rel' => $gallery_id,
    ),
  );
  $link_tag = l($link_text, '', $link_options);

  // The outside div is there to hide all of the divs because if the specific Colorbox
  // div is hidden it won't show up as a Colorbox.
  return $link_tag . '<div style="display: none;"><div id="colorbox-inline-' . $i . '">' . $popup . '</div></div>';
}