You are here

function lightbox2_handler_field_lightbox2::render in Lightbox2 8

Same name in this branch
  1. 8 lightbox2_handler_field_lightbox2.inc \lightbox2_handler_field_lightbox2::render()
  2. 8 src/lightbox2_handler_field_lightbox2.php \Drupal\lightbox2\lightbox2_handler_field_lightbox2::render()

Render the trigger field and its linked popup information.

File

src/lightbox2_handler_field_lightbox2.php, line 118
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.

Namespace

Drupal\lightbox2

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.
      $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
      $link = url($path, array(
        'absolute' => TRUE,
      ));
    }

    // Get the token information and generate the value for the popup and the
    // caption.
    $tokens = $this
      ->get_render_tokens($this->options['alter']);
    $popup = \Drupal\Component\Utility\Xss::filterAdmin($this->options['popup']);
    $caption = \Drupal\Component\Utility\Xss::filterAdmin($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) : '');
    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>\n                <div style='display: none;'><div id='lightbox-popup-{$i}' class='lightbox-popup'>{$popup}</div></div>";
  }
  else {
    return;
  }
}