You are here

Url.php in Views (for Drupal 7) 8.3

File

lib/Drupal/views/Plugin/views/field/Url.php
View source
<?php

/**
 * @file
 * Definition of Drupal\views\Plugin\views\field\Url.
 */
namespace Drupal\views\Plugin\views\field;

use Drupal\Core\Annotation\Plugin;

/**
 * Field handler to provide simple renderer that turns a URL into a clickable link.
 *
 * @ingroup views_field_handlers
 *
 * @Plugin(
 *   id = "url"
 * )
 */
class Url extends FieldPluginBase {
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['display_as_link'] = array(
      'default' => TRUE,
      'bool' => TRUE,
    );
    return $options;
  }

  /**
   * Provide link to the page being visited.
   */
  public function buildOptionsForm(&$form, &$form_state) {
    $form['display_as_link'] = array(
      '#title' => t('Display as link'),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['display_as_link']),
    );
    parent::buildOptionsForm($form, $form_state);
  }
  function render($values) {
    $value = $this
      ->get_value($values);
    if (!empty($this->options['display_as_link'])) {
      return l($this
        ->sanitizeValue($value), $value, array(
        'html' => TRUE,
      ));
    }
    else {
      return $this
        ->sanitizeValue($value, 'url');
    }
  }

}

Classes

Namesort descending Description
Url Field handler to provide simple renderer that turns a URL into a clickable link.