You are here

function views_handler_area_link::render in Views link area 7

Same name and namespace in other branches
  1. 6 views_handler_area_link.inc \views_handler_area_link::render()

Render the area.

Overrides views_handler_area::render

File

./views_handler_area_link.inc, line 188

Class

views_handler_area_link

Code

function render($empty = FALSE) {
  $value = '';
  if ($empty && empty($this->options['empty'])) {
    return '';
  }
  $tokens = $this
    ->get_render_tokens();

  // Replace any tokens in the text.
  $text = strtr($this->options['text'], $tokens);

  // Replace any tokens in the path.
  $path = strtr($this->options['path'], $tokens);
  if (!empty($this->options['prefix'])) {
    $value .= filter_xss_admin(strtr($this->options['prefix'], $tokens));
  }

  // Check that the user has access to the menu router item, but only if the
  // path is for a valid menu router item, so that external URLs or paths not
  // handled by Drupal's menu router are always permitted.
  $router_item = menu_get_item($path);
  if ($router_item && !$router_item['access']) {
    return '';
  }

  // Where we store tokenized values.
  $link_properties = array();

  // Options that will go into the attributes array for url().
  $attribute_keys = array(
    'title',
    'target',
    'rel',
    'class',
  );

  // Other options that we need to put into link properties.
  $option_keys = array_merge(array(
    'anchor',
    'text',
    'path',
  ), $attribute_keys);
  if (!empty($this->options['querystring'])) {

    // This is an ugly way to do it, but Drupal 7 now takes an array for
    // query instead of a string.  That's good, but makes our string field
    // not work.  This should get switched to a multi-value interface of
    // some kind instead of ugly string parsing. @todo
    $querystring = strtr($this->options['querystring'], $tokens);
    $link_properties['query'] = drupal_get_query_array($querystring);
  }
  if (!empty($this->options['return'])) {
    $destination = drupal_get_destination();
    $link_properties['query']['destination'] = $destination['destination'];
  }

  // Grab all of our options and tokenize them if necessary.
  foreach ($option_keys as $key) {
    if (empty($this->options[$key])) {
      continue;
    }
    if ('anchor' == $key) {
      $link_properties['fragment'] = $this->options[$key];
    }
    else {
      $link_properties[$key] = $this->options[$key];
    }

    // Apply the argument substitutions.
    if (!empty($tokens)) {
      $link_properties[$key] = str_replace(array_keys($tokens), array_values($tokens), $link_properties[$key]);
    }

    // Apply the more advanced tokenization.
    if ($this->options['tokenize']) {
      $link_properties[$key] = $this->view->style_plugin
        ->tokenize_value($link_properties[$key], 0);
    }
  }
  if (empty($link_properties['attributes'])) {
    $link_properties['attributes'] = array();
  }

  // Move our attributes into an attribute array for ease of use with url().
  foreach ($attribute_keys as $key) {
    if (!empty($link_properties[$key])) {
      $link_properties['attributes'][$key] = $link_properties[$key];
      if ('class' === $key) {
        $link_properties['attributes'][$key] = explode(' ', $link_properties['attributes'][$key]);
      }
    }
  }
  if ($this->options['html']) {
    $text = filter_xss_admin($text);
    $link_properties['html'] = TRUE;
  }
  else {

    // Make sure all HTML entities are decoded before passing to l().
    while (decode_entities($text) != $text) {
      $text = decode_entities($text);
    }
  }
  $value .= l($text, $path, $link_properties);
  if (!empty($this->options['suffix'])) {
    $value .= filter_xss_admin(strtr($this->options['suffix'], $tokens));
  }
  return $value;
}