You are here

abstract class FieldPluginBase in Views (for Drupal 7) 8.3

Base field handler that has no options and renders an unformatted field.

Definition terms:

  • additional fields: An array of fields that should be added to the query for some purpose. The array is in the form of: array('identifier' => array('table' => tablename, 'field' => fieldname); as many fields as are necessary may be in this array.
  • click sortable: If TRUE, this field may be click sorted.

Hierarchy

Expanded class hierarchy of FieldPluginBase

Related topics

29 files declare their use of FieldPluginBase
AccesslogPath.php in lib/Views/statistics/Plugin/views/field/AccesslogPath.php
Definition of Views\statistics\Plugin\views\field\AccesslogPath.
Category.php in lib/Views/aggregator/Plugin/views/field/Category.php
Definition of Views\aggregator\Plugin\views\field\Category.
Comment.php in lib/Views/comment/Plugin/views/field/Comment.php
Definition of Views\comment\Plugin\views\field\Comment.
Depth.php in lib/Views/comment/Plugin/views/field/Depth.php
Definition of Views\comment\Plugin\views\field\Depth.
Extension.php in lib/Views/file/Plugin/views/field/Extension.php
Definition of views_handler_field_file_extension.

... See full list

File

lib/Drupal/views/Plugin/views/field/FieldPluginBase.php, line 51
Definition of Drupal\views\Plugin\views\field\FieldPluginBase.

Namespace

Drupal\views\Plugin\views\field
View source
abstract class FieldPluginBase extends HandlerBase {
  var $field_alias = 'unknown';
  var $aliases = array();

  /**
   * The field value prior to any rewriting.
   *
   * @var mixed
   */
  public $original_value = NULL;

  /**
   * @var array
   * Stores additional fields which get's added to the query.
   * The generated aliases are stored in $aliases.
   */
  var $additional_fields = array();

  /**
   * Overrides Drupal\views\Plugin\views\HandlerBase::init().
   */
  public function init(ViewExecutable $view, &$options) {
    parent::init($view, $options);
    $this->additional_fields = array();
    if (!empty($this->definition['additional fields'])) {
      $this->additional_fields = $this->definition['additional fields'];
    }
    if (!isset($this->options['exclude'])) {
      $this->options['exclude'] = '';
    }
  }

  /**
   * Determine if this field can allow advanced rendering.
   *
   * Fields can set this to FALSE if they do not wish to allow
   * token based rewriting or link-making.
   */
  function allow_advanced_render() {
    return TRUE;
  }

  /**
   * Called to add the field to a query.
   */
  public function query() {
    $this
      ->ensureMyTable();

    // Add the field.
    $params = $this->options['group_type'] != 'group' ? array(
      'function' => $this->options['group_type'],
    ) : array();
    $this->field_alias = $this->query
      ->add_field($this->tableAlias, $this->realField, NULL, $params);
    $this
      ->add_additional_fields();
  }

  /**
   * Add 'additional' fields to the query.
   *
   * @param $fields
   * An array of fields. The key is an identifier used to later find the
   * field alias used. The value is either a string in which case it's
   * assumed to be a field on this handler's table; or it's an array in the
   * form of
   * @code array('table' => $tablename, 'field' => $fieldname) @endcode
   */
  function add_additional_fields($fields = NULL) {
    if (!isset($fields)) {

      // notice check
      if (empty($this->additional_fields)) {
        return;
      }
      $fields = $this->additional_fields;
    }
    $group_params = array();
    if ($this->options['group_type'] != 'group') {
      $group_params = array(
        'function' => $this->options['group_type'],
      );
    }
    if (!empty($fields) && is_array($fields)) {
      foreach ($fields as $identifier => $info) {
        if (is_array($info)) {
          if (isset($info['table'])) {
            $table_alias = $this->query
              ->ensure_table($info['table'], $this->relationship);
          }
          else {
            $table_alias = $this->tableAlias;
          }
          if (empty($table_alias)) {
            debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array(
              '@handler' => $this->definition['handler'],
              '@identifier' => $identifier,
              '@table' => $info['table'],
            )));
            $this->aliases[$identifier] = 'broken';
            continue;
          }
          $params = array();
          if (!empty($info['params'])) {
            $params = $info['params'];
          }
          $params += $group_params;
          $this->aliases[$identifier] = $this->query
            ->add_field($table_alias, $info['field'], NULL, $params);
        }
        else {
          $this->aliases[$info] = $this->query
            ->add_field($this->tableAlias, $info, NULL, $group_params);
        }
      }
    }
  }

  /**
   * Called to determine what to tell the clicksorter.
   */
  function click_sort($order) {
    if (isset($this->field_alias)) {

      // Since fields should always have themselves already added, just
      // add a sort on the field.
      $params = $this->options['group_type'] != 'group' ? array(
        'function' => $this->options['group_type'],
      ) : array();
      $this->query
        ->add_orderby(NULL, NULL, $order, $this->field_alias, $params);
    }
  }

  /**
   * Determine if this field is click sortable.
   */
  function click_sortable() {
    return !empty($this->definition['click sortable']);
  }

  /**
   * Get this field's label.
   */
  public function label() {
    if (!isset($this->options['label'])) {
      return '';
    }
    return $this->options['label'];
  }

  /**
   * Return an HTML element based upon the field's element type.
   */
  function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
    if ($none_supported) {
      if ($this->options['element_type'] === '0') {
        return '';
      }
    }
    if ($this->options['element_type']) {
      return check_plain($this->options['element_type']);
    }
    if ($default_empty) {
      return '';
    }
    if ($inline) {
      return 'span';
    }
    if (isset($this->definition['element type'])) {
      return $this->definition['element type'];
    }
    return 'span';
  }

  /**
   * Return an HTML element for the label based upon the field's element type.
   */
  function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
    if ($none_supported) {
      if ($this->options['element_label_type'] === '0') {
        return '';
      }
    }
    if ($this->options['element_label_type']) {
      return check_plain($this->options['element_label_type']);
    }
    if ($default_empty) {
      return '';
    }
    return 'span';
  }

  /**
   * Return an HTML element for the wrapper based upon the field's element type.
   */
  function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
    if ($none_supported) {
      if ($this->options['element_wrapper_type'] === '0') {
        return 0;
      }
    }
    if ($this->options['element_wrapper_type']) {
      return check_plain($this->options['element_wrapper_type']);
    }
    if ($default_empty) {
      return '';
    }
    return 'div';
  }

  /**
   * Provide a list of elements valid for field HTML.
   *
   * This function can be overridden by fields that want more or fewer
   * elements available, though this seems like it would be an incredibly
   * rare occurence.
   */
  function get_elements() {
    static $elements = NULL;
    if (!isset($elements)) {

      // @todo Add possible html5 elements.
      $elements = array(
        '' => t(' - Use default -'),
        '0' => t('- None -'),
      );
      $elements += config('views.settings')
        ->get('field_rewrite_elements');
    }
    return $elements;
  }

  /**
   * Return the class of the field.
   */
  function element_classes($row_index = NULL) {
    $classes = explode(' ', $this->options['element_class']);
    foreach ($classes as &$class) {
      $class = $this
        ->tokenize_value($class, $row_index);
      $class = drupal_clean_css_identifier($class);
    }
    return implode(' ', $classes);
  }

  /**
   * Replace a value with tokens from the last field.
   *
   * This function actually figures out which field was last and uses its
   * tokens so they will all be available.
   */
  function tokenize_value($value, $row_index = NULL) {
    if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) {
      $fake_item = array(
        'alter_text' => TRUE,
        'text' => $value,
      );

      // Use isset() because empty() will trigger on 0 and 0 is
      // the first row.
      if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
        $tokens = $this->view->style_plugin->render_tokens[$row_index];
      }
      else {

        // Get tokens from the last field.
        $last_field = end($this->view->field);
        if (isset($last_field->last_tokens)) {
          $tokens = $last_field->last_tokens;
        }
        else {
          $tokens = $last_field
            ->get_render_tokens($fake_item);
        }
      }
      $value = strip_tags($this
        ->render_altered($fake_item, $tokens));
      if (!empty($this->options['alter']['trim_whitespace'])) {
        $value = trim($value);
      }
    }
    return $value;
  }

  /**
   * Return the class of the field's label.
   */
  function element_label_classes($row_index = NULL) {
    $classes = explode(' ', $this->options['element_label_class']);
    foreach ($classes as &$class) {
      $class = $this
        ->tokenize_value($class, $row_index);
      $class = drupal_clean_css_identifier($class);
    }
    return implode(' ', $classes);
  }

  /**
   * Return the class of the field's wrapper.
   */
  function element_wrapper_classes($row_index = NULL) {
    $classes = explode(' ', $this->options['element_wrapper_class']);
    foreach ($classes as &$class) {
      $class = $this
        ->tokenize_value($class, $row_index);
      $class = drupal_clean_css_identifier($class);
    }
    return implode(' ', $classes);
  }

  /**
   * Get the entity matching the current row and relationship.
   *
   * @param $values
   *   An object containing all retrieved values.
   */
  function get_entity($values) {
    $relationship_id = $this->options['relationship'];
    if ($relationship_id == 'none') {
      return $values->_entity;
    }
    else {
      return $values->_relationship_entities[$relationship_id];
    }
  }

  /**
   * Get the value that's supposed to be rendered.
   *
   * This api exists so that other modules can easy set the values of the field
   * without having the need to change the render method as well.
   *
   * @param $values
   *   An object containing all retrieved values.
   * @param $field
   *   Optional name of the field where the value is stored.
   */
  function get_value($values, $field = NULL) {
    $alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
    if (isset($values->{$alias})) {
      return $values->{$alias};
    }
  }

  /**
   * Determines if this field will be available as an option to group the result
   * by in the style settings.
   *
   * @return bool
   *  TRUE if this field handler is groupable, otherwise FALSE.
   */
  function use_string_group_by() {
    return TRUE;
  }
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['label'] = array(
      'default' => $this->definition['title'],
      'translatable' => TRUE,
    );
    $options['exclude'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    $options['alter'] = array(
      'contains' => array(
        'alter_text' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'text' => array(
          'default' => '',
          'translatable' => TRUE,
        ),
        'make_link' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'path' => array(
          'default' => '',
        ),
        'absolute' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'external' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'replace_spaces' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'path_case' => array(
          'default' => 'none',
          'translatable' => FALSE,
        ),
        'trim_whitespace' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'alt' => array(
          'default' => '',
          'translatable' => TRUE,
        ),
        'rel' => array(
          'default' => '',
        ),
        'link_class' => array(
          'default' => '',
        ),
        'prefix' => array(
          'default' => '',
          'translatable' => TRUE,
        ),
        'suffix' => array(
          'default' => '',
          'translatable' => TRUE,
        ),
        'target' => array(
          'default' => '',
          'translatable' => TRUE,
        ),
        'nl2br' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'max_length' => array(
          'default' => '',
        ),
        'word_boundary' => array(
          'default' => TRUE,
          'bool' => TRUE,
        ),
        'ellipsis' => array(
          'default' => TRUE,
          'bool' => TRUE,
        ),
        'more_link' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'more_link_text' => array(
          'default' => '',
          'translatable' => TRUE,
        ),
        'more_link_path' => array(
          'default' => '',
        ),
        'strip_tags' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'trim' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
        'preserve_tags' => array(
          'default' => '',
        ),
        'html' => array(
          'default' => FALSE,
          'bool' => TRUE,
        ),
      ),
    );
    $options['element_type'] = array(
      'default' => '',
    );
    $options['element_class'] = array(
      'default' => '',
    );
    $options['element_label_type'] = array(
      'default' => '',
    );
    $options['element_label_class'] = array(
      'default' => '',
    );
    $options['element_label_colon'] = array(
      'default' => TRUE,
      'bool' => TRUE,
    );
    $options['element_wrapper_type'] = array(
      'default' => '',
    );
    $options['element_wrapper_class'] = array(
      'default' => '',
    );
    $options['element_default_classes'] = array(
      'default' => TRUE,
      'bool' => TRUE,
    );
    $options['empty'] = array(
      'default' => '',
      'translatable' => TRUE,
    );
    $options['hide_empty'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    $options['empty_zero'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    $options['hide_alter_empty'] = array(
      'default' => TRUE,
      'bool' => TRUE,
    );
    return $options;
  }

  /**
   * Performs some cleanup tasks on the options array before saving it.
   */
  public function submitOptionsForm(&$form, &$form_state) {
    $options =& $form_state['values']['options'];
    $types = array(
      'element_type',
      'element_label_type',
      'element_wrapper_type',
    );
    $classes = array_combine(array(
      'element_class',
      'element_label_class',
      'element_wrapper_class',
    ), $types);
    foreach ($types as $type) {
      if (!$options[$type . '_enable']) {
        $options[$type] = '';
      }
    }
    foreach ($classes as $class => $type) {
      if (!$options[$class . '_enable'] || !$options[$type . '_enable']) {
        $options[$class] = '';
      }
    }
    if (empty($options['custom_label'])) {
      $options['label'] = '';
      $options['element_label_colon'] = FALSE;
    }
  }

  /**
   * Default options form that provides the label widget that all fields
   * should have.
   */
  public function buildOptionsForm(&$form, &$form_state) {
    parent::buildOptionsForm($form, $form_state);
    $label = $this
      ->label();
    $form['custom_label'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create a label'),
      '#description' => t('Enable to create a label for this field.'),
      '#default_value' => $label !== '',
      '#weight' => -103,
    );
    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label'),
      '#default_value' => $label,
      '#states' => array(
        'visible' => array(
          ':input[name="options[custom_label]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#weight' => -102,
    );
    $form['element_label_colon'] = array(
      '#type' => 'checkbox',
      '#title' => t('Place a colon after the label'),
      '#default_value' => $this->options['element_label_colon'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[custom_label]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#weight' => -101,
    );
    $form['exclude'] = array(
      '#type' => 'checkbox',
      '#title' => t('Exclude from display'),
      '#default_value' => $this->options['exclude'],
      '#description' => t('Enable to load this field as hidden. Often used to group fields, or to use as token in another field.'),
      '#weight' => -100,
    );
    $form['style_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Style settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => 99,
    );
    $form['element_type_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Customize field HTML'),
      '#default_value' => !empty($this->options['element_type']) || (string) $this->options['element_type'] == '0' || !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
      '#fieldset' => 'style_settings',
    );
    $form['element_type'] = array(
      '#title' => t('HTML element'),
      '#options' => $this
        ->get_elements(),
      '#type' => 'select',
      '#default_value' => $this->options['element_type'],
      '#description' => t('Choose the HTML element to wrap around this field, e.g. H1, H2, etc.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#fieldset' => 'style_settings',
    );
    $form['element_class_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create a CSS class'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#default_value' => !empty($this->options['element_class']) || (string) $this->options['element_class'] == '0',
      '#fieldset' => 'style_settings',
    );
    $form['element_class'] = array(
      '#title' => t('CSS class'),
      '#description' => t('You may use token substitutions from the rewriting section in this class.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['element_class'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_type_enable]"]' => array(
            'checked' => TRUE,
          ),
          ':input[name="options[element_class_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#fieldset' => 'style_settings',
    );
    $form['element_label_type_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Customize label HTML'),
      '#default_value' => !empty($this->options['element_label_type']) || (string) $this->options['element_label_type'] == '0' || !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
      '#fieldset' => 'style_settings',
    );
    $form['element_label_type'] = array(
      '#title' => t('Label HTML element'),
      '#options' => $this
        ->get_elements(FALSE),
      '#type' => 'select',
      '#default_value' => $this->options['element_label_type'],
      '#description' => t('Choose the HTML element to wrap around this label, e.g. H1, H2, etc.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_label_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#fieldset' => 'style_settings',
    );
    $form['element_label_class_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create a CSS class'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_label_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
      '#fieldset' => 'style_settings',
    );
    $form['element_label_class'] = array(
      '#title' => t('CSS class'),
      '#description' => t('You may use token substitutions from the rewriting section in this class.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['element_label_class'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_label_type_enable]"]' => array(
            'checked' => TRUE,
          ),
          ':input[name="options[element_label_class_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#fieldset' => 'style_settings',
    );
    $form['element_wrapper_type_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Customize field and label wrapper HTML'),
      '#default_value' => !empty($this->options['element_wrapper_type']) || (string) $this->options['element_wrapper_type'] == '0' || !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
      '#fieldset' => 'style_settings',
    );
    $form['element_wrapper_type'] = array(
      '#title' => t('Wrapper HTML element'),
      '#options' => $this
        ->get_elements(FALSE),
      '#type' => 'select',
      '#default_value' => $this->options['element_wrapper_type'],
      '#description' => t('Choose the HTML element to wrap around this field and label, e.g. H1, H2, etc. This may not be used if the field and label are not rendered together, such as with a table.'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_wrapper_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#fieldset' => 'style_settings',
    );
    $form['element_wrapper_class_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create a CSS class'),
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_wrapper_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#default_value' => !empty($this->options['element_wrapper_class']) || (string) $this->options['element_wrapper_class'] == '0',
      '#fieldset' => 'style_settings',
    );
    $form['element_wrapper_class'] = array(
      '#title' => t('CSS class'),
      '#description' => t('You may use token substitutions from the rewriting section in this class.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['element_wrapper_class'],
      '#states' => array(
        'visible' => array(
          ':input[name="options[element_wrapper_class_enable]"]' => array(
            'checked' => TRUE,
          ),
          ':input[name="options[element_wrapper_type_enable]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
      '#fieldset' => 'style_settings',
    );
    $form['element_default_classes'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add default classes'),
      '#default_value' => $this->options['element_default_classes'],
      '#description' => t('Use default Views classes to identify the field, field label and field content.'),
      '#fieldset' => 'style_settings',
    );
    $form['alter'] = array(
      '#title' => t('Rewrite results'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => 100,
    );
    if ($this
      ->allow_advanced_render()) {
      $form['alter']['#tree'] = TRUE;
      $form['alter']['alter_text'] = array(
        '#type' => 'checkbox',
        '#title' => t('Rewrite the output of this field'),
        '#description' => t('Enable to override the output of this field with custom text or replacement tokens.'),
        '#default_value' => $this->options['alter']['alter_text'],
      );
      $form['alter']['text'] = array(
        '#title' => t('Text'),
        '#type' => 'textarea',
        '#default_value' => $this->options['alter']['text'],
        '#description' => t('The text to display for this field. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][alter_text]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['make_link'] = array(
        '#type' => 'checkbox',
        '#title' => t('Output this field as a link'),
        '#description' => t('If checked, this field will be made into a link. The destination must be given below.'),
        '#default_value' => $this->options['alter']['make_link'],
      );
      $form['alter']['path'] = array(
        '#title' => t('Link path'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['path'],
        '#description' => t('The Drupal path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
        '#maxlength' => 255,
      );
      $form['alter']['absolute'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use absolute path'),
        '#default_value' => $this->options['alter']['absolute'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['replace_spaces'] = array(
        '#type' => 'checkbox',
        '#title' => t('Replace spaces with dashes'),
        '#default_value' => $this->options['alter']['replace_spaces'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['external'] = array(
        '#type' => 'checkbox',
        '#title' => t('External server URL'),
        '#default_value' => $this->options['alter']['external'],
        '#description' => t("Links to an external server using a full URL: e.g. 'http://www.example.com' or 'www.example.com'."),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['path_case'] = array(
        '#type' => 'select',
        '#title' => t('Transform the case'),
        '#description' => t('When printing url paths, how to transform the case of the filter value.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
        '#options' => array(
          'none' => t('No transform'),
          'upper' => t('Upper case'),
          'lower' => t('Lower case'),
          'ucfirst' => t('Capitalize first letter'),
          'ucwords' => t('Capitalize each word'),
        ),
        '#default_value' => $this->options['alter']['path_case'],
      );
      $form['alter']['link_class'] = array(
        '#title' => t('Link class'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['link_class'],
        '#description' => t('The CSS class to apply to the link.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['alt'] = array(
        '#title' => t('Title text'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['alt'],
        '#description' => t('Text to place as "title" text which most browsers display as a tooltip when hovering over the link.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['rel'] = array(
        '#title' => t('Rel Text'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['rel'],
        '#description' => t('Include Rel attribute for use in lightbox2 or other javascript utility.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['prefix'] = array(
        '#title' => t('Prefix text'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['prefix'],
        '#description' => t('Any text to display before this link. You may include HTML.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['suffix'] = array(
        '#title' => t('Suffix text'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['suffix'],
        '#description' => t('Any text to display after this link. You may include HTML.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['target'] = array(
        '#title' => t('Target'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['target'],
        '#description' => t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][make_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );

      // Get a list of the available fields and arguments for token replacement.
      $options = array();
      foreach ($this->view->display_handler
        ->getHandlers('field') as $field => $handler) {
        $options[t('Fields')]["[{$field}]"] = $handler
          ->adminLabel();

        // We only use fields up to (and including) this one.
        if ($field == $this->options['id']) {
          break;
        }
      }
      $count = 0;

      // This lets us prepare the key as we want it printed.
      foreach ($this->view->display_handler
        ->getHandlers('argument') as $arg => $handler) {
        $options[t('Arguments')]['%' . ++$count] = t('@argument title', array(
          '@argument' => $handler
            ->adminLabel(),
        ));
        $options[t('Arguments')]['!' . $count] = t('@argument input', array(
          '@argument' => $handler
            ->adminLabel(),
        ));
      }
      $this
        ->document_self_tokens($options[t('Fields')]);

      // Default text.
      $output = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');

      // We have some options, so make a list.
      if (!empty($options)) {
        $output = t('<p>The following tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.
If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or  \'%5D\' or they will get replaced with empty space.</p>');
        foreach (array_keys($options) as $type) {
          if (!empty($options[$type])) {
            $items = array();
            foreach ($options[$type] as $key => $value) {
              $items[] = $key . ' == ' . $value;
            }
            $output .= theme('item_list', array(
              'items' => $items,
              'type' => $type,
            ));
          }
        }
      }

      // This construct uses 'hidden' and not markup because process doesn't
      // run. It also has an extra div because the dependency wants to hide
      // the parent in situations like this, so we need a second div to
      // make this work.
      $form['alter']['help'] = array(
        '#type' => 'fieldset',
        '#title' => t('Replacement patterns'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#value' => $output,
        '#states' => array(
          'visible' => array(
            array(
              ':input[name="options[alter][make_link]"]' => array(
                'checked' => TRUE,
              ),
            ),
            array(
              ':input[name="options[alter][alter_text]"]' => array(
                'checked' => TRUE,
              ),
            ),
            array(
              ':input[name="options[alter][more_link]"]' => array(
                'checked' => TRUE,
              ),
            ),
          ),
        ),
      );
      $form['alter']['trim'] = array(
        '#type' => 'checkbox',
        '#title' => t('Trim this field to a maximum length'),
        '#description' => t('Enable to trim the field to a maximum length of characters'),
        '#default_value' => $this->options['alter']['trim'],
      );
      $form['alter']['max_length'] = array(
        '#title' => t('Maximum length'),
        '#type' => 'textfield',
        '#default_value' => $this->options['alter']['max_length'],
        '#description' => t('The maximum number of characters this field can be.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['word_boundary'] = array(
        '#type' => 'checkbox',
        '#title' => t('Trim only on a word boundary'),
        '#description' => t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'),
        '#default_value' => $this->options['alter']['word_boundary'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['ellipsis'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add an ellipsis'),
        '#description' => t('If checked, a "..." will be added if a field was trimmed.'),
        '#default_value' => $this->options['alter']['ellipsis'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['more_link'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add a read-more link if output is trimmed.'),
        '#description' => t('If checked, a read-more link will be added at the end of the trimmed output'),
        '#default_value' => $this->options['alter']['more_link'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['more_link_text'] = array(
        '#type' => 'textfield',
        '#title' => t('More link text'),
        '#default_value' => $this->options['alter']['more_link_text'],
        '#description' => t('The text which will be displayed on the more link. You may enter data from this view as per the "Replacement patterns" above.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
            ':input[name="options[alter][more_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['more_link_path'] = array(
        '#type' => 'textfield',
        '#title' => t('More link path'),
        '#default_value' => $this->options['alter']['more_link_path'],
        '#description' => t('The path which is used for the more link. You may enter data from this view as per the "Replacement patterns" above.'),
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
            ':input[name="options[alter][more_link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['html'] = array(
        '#type' => 'checkbox',
        '#title' => t('Field can contain HTML'),
        '#description' => t('If checked, HTML corrector will be run to ensure tags are properly closed after trimming.'),
        '#default_value' => $this->options['alter']['html'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][trim]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['strip_tags'] = array(
        '#type' => 'checkbox',
        '#title' => t('Strip HTML tags'),
        '#description' => t('If checked, all HTML tags will be stripped.'),
        '#default_value' => $this->options['alter']['strip_tags'],
      );
      $form['alter']['preserve_tags'] = array(
        '#type' => 'textfield',
        '#title' => t('Preserve certain tags'),
        '#description' => t('List the tags that need to be preserved during the stripping process. example &quot;&lt;p&gt; &lt;br&gt;&quot; which will preserve all p and br elements'),
        '#default_value' => $this->options['alter']['preserve_tags'],
        '#states' => array(
          'visible' => array(
            ':input[name="options[alter][strip_tags]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $form['alter']['trim_whitespace'] = array(
        '#type' => 'checkbox',
        '#title' => t('Remove whitespace'),
        '#description' => t('If checked, all whitespaces at the beginning and the end of the output will be removed.'),
        '#default_value' => $this->options['alter']['trim_whitespace'],
      );
      $form['alter']['nl2br'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert newlines to HTML &lt;br&gt; tags'),
        '#description' => t('If checked, all newlines chars (e.g. \\n) are converted into HTML &lt;br&gt; tags.'),
        '#default_value' => $this->options['alter']['nl2br'],
      );
    }
    $form['empty_field_behavior'] = array(
      '#type' => 'fieldset',
      '#title' => t('No results behavior'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => 100,
    );
    $form['empty'] = array(
      '#type' => 'textarea',
      '#title' => t('No results text'),
      '#default_value' => $this->options['empty'],
      '#description' => t('Provide text to display if this field contains an empty result. You may include HTML. You may enter data from this view as per the "Replacement patterns" in the "Rewrite Results" section below.'),
      '#fieldset' => 'empty_field_behavior',
    );
    $form['empty_zero'] = array(
      '#type' => 'checkbox',
      '#title' => t('Count the number 0 as empty'),
      '#default_value' => $this->options['empty_zero'],
      '#description' => t('Enable to display the "no results text" if the field contains the number 0.'),
      '#fieldset' => 'empty_field_behavior',
    );
    $form['hide_empty'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide if empty'),
      '#default_value' => $this->options['hide_empty'],
      '#description' => t('Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the "Hide rewriting if empty" checkbox.'),
      '#fieldset' => 'empty_field_behavior',
    );
    $form['hide_alter_empty'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide rewriting if empty'),
      '#default_value' => $this->options['hide_alter_empty'],
      '#description' => t('Do not display rewritten content if this field is empty.'),
      '#fieldset' => 'empty_field_behavior',
    );
  }

  /**
   * Provide extra data to the administration form
   */
  public function adminSummary() {
    return $this
      ->label();
  }

  /**
   * Run before any fields are rendered.
   *
   * This gives the handlers some time to set up before any handler has
   * been rendered.
   *
   * @param $values
   *   An array of all objects returned from the query.
   */
  function pre_render(&$values) {
  }

  /**
   * Render the field.
   *
   * @param $values
   *   The values retrieved from the database.
   */
  function render($values) {
    $value = $this
      ->get_value($values);
    return $this
      ->sanitizeValue($value);
  }

  /**
   * Render a field using advanced settings.
   *
   * This renders a field normally, then decides if render-as-link and
   * text-replacement rendering is necessary.
   */
  function advanced_render($values) {
    if ($this
      ->allow_advanced_render() && method_exists($this, 'render_item')) {
      $raw_items = $this
        ->get_items($values);

      // If there are no items, set the original value to NULL.
      if (empty($raw_items)) {
        $this->original_value = NULL;
      }
    }
    else {
      $value = $this
        ->render($values);
      if (is_array($value)) {
        $value = drupal_render($value);
      }
      $this->last_render = $value;
      $this->original_value = $value;
    }
    if ($this
      ->allow_advanced_render()) {
      $tokens = NULL;
      if (method_exists($this, 'render_item')) {
        $items = array();
        foreach ($raw_items as $count => $item) {
          $value = $this
            ->render_item($count, $item);
          if (is_array($value)) {
            $value = drupal_render($value);
          }
          $this->last_render = $value;
          $this->original_value = $this->last_render;
          $alter = $item + $this->options['alter'];
          $alter['phase'] = VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM;
          $items[] = $this
            ->render_text($alter);
        }
        $value = $this
          ->render_items($items);
      }
      else {
        $alter = array(
          'phase' => VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY,
        ) + $this->options['alter'];
        $value = $this
          ->render_text($alter);
      }
      if (is_array($value)) {
        $value = drupal_render($value);
      }

      // This happens here so that render_as_link can get the unaltered value of
      // this field as a token rather than the altered value.
      $this->last_render = $value;
    }
    if (empty($this->last_render)) {
      if ($this
        ->is_value_empty($this->last_render, $this->options['empty_zero'], FALSE)) {
        $alter = $this->options['alter'];
        $alter['alter_text'] = 1;
        $alter['text'] = $this->options['empty'];
        $alter['phase'] = VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY;
        $this->last_render = $this
          ->render_text($alter);
      }
    }
    return $this->last_render;
  }

  /**
   * Checks if a field value is empty.
   *
   * @param $value
   *   The field value.
   * @param bool $empty_zero
   *   Whether or not this field is configured to consider 0 as empty.
   * @param bool $no_skip_empty
   *   Whether or not to use empty() to check the value.
   *
   * @return bool
   * TRUE if the value is considered empty, FALSE otherwise.
   */
  function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
    if (!isset($value)) {
      $empty = TRUE;
    }
    else {
      $empty = $empty_zero || $value !== 0 && $value !== '0';
    }
    if ($no_skip_empty) {
      $empty = empty($value) && $empty;
    }
    return $empty;
  }

  /**
   * Perform an advanced text render for the item.
   *
   * This is separated out as some fields may render lists, and this allows
   * each item to be handled individually.
   */
  function render_text($alter) {
    $value = $this->last_render;
    if (!empty($alter['alter_text']) && $alter['text'] !== '') {
      $tokens = $this
        ->get_render_tokens($alter);
      $value = $this
        ->render_altered($alter, $tokens);
    }
    if (!empty($this->options['alter']['trim_whitespace'])) {
      $value = trim($value);
    }

    // Check if there should be no further rewrite for empty values.
    $no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this
      ->is_value_empty($this->original_value, $this->options['empty_zero']);

    // Check whether the value is empty and return nothing, so the field isn't rendered.
    // First check whether the field should be hidden if the value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty = FALSE).
    // For numeric values you can specify whether "0"/0 should be empty.
    if (($this->options['hide_empty'] && empty($value) || $alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty) && $this
      ->is_value_empty($value, $this->options['empty_zero'], FALSE)) {
      return '';
    }

    // Only in empty phase.
    if ($alter['phase'] == VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty) {

      // If we got here then $alter contains the value of "No results text"
      // and so there is nothing left to do.
      return $value;
    }
    if (!empty($alter['strip_tags'])) {
      $value = strip_tags($value, $alter['preserve_tags']);
    }
    $suffix = '';
    if (!empty($alter['trim']) && !empty($alter['max_length'])) {
      $length = strlen($value);
      $value = $this
        ->render_trim_text($alter, $value);
      if ($this->options['alter']['more_link'] && strlen($value) < $length) {
        $tokens = $this
          ->get_render_tokens($alter);
        $more_link_text = $this->options['alter']['more_link_text'] ? $this->options['alter']['more_link_text'] : t('more');
        $more_link_text = strtr(filter_xss_admin($more_link_text), $tokens);
        $more_link_path = $this->options['alter']['more_link_path'];
        $more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));

        // Take sure that paths which was runned through url() does work as well.
        $base_path = base_path();

        // Checks whether the path starts with the base_path.
        if (strpos($more_link_path, $base_path) === 0) {
          $more_link_path = drupal_substr($more_link_path, drupal_strlen($base_path));
        }
        $more_link = l($more_link_text, $more_link_path, array(
          'attributes' => array(
            'class' => array(
              'views-more-link',
            ),
          ),
        ));
        $suffix .= " " . $more_link;
      }
    }
    if (!empty($alter['nl2br'])) {
      $value = nl2br($value);
    }
    $this->last_render_text = $value;
    if (!empty($alter['make_link']) && !empty($alter['path'])) {
      if (!isset($tokens)) {
        $tokens = $this
          ->get_render_tokens($alter);
      }
      $value = $this
        ->render_as_link($alter, $value, $tokens);
    }
    return $value . $suffix;
  }

  /**
   * Render this field as altered text, from a fieldset set by the user.
   */
  function render_altered($alter, $tokens) {

    // Filter this right away as our substitutions are already sanitized.
    $value = filter_xss_admin($alter['text']);
    $value = strtr($value, $tokens);
    return $value;
  }

  /**
   * Trim the field down to the specified length.
   */
  function render_trim_text($alter, $value) {
    if (!empty($alter['strip_tags'])) {

      // NOTE: It's possible that some external fields might override the
      // element type.
      $this->definition['element type'] = 'span';
    }
    return views_trim_text($alter, $value);
  }

  /**
   * Render this field as a link, with the info from a fieldset set by
   * the user.
   */
  function render_as_link($alter, $text, $tokens) {
    $value = '';
    if (!empty($alter['prefix'])) {
      $value .= filter_xss_admin(strtr($alter['prefix'], $tokens));
    }
    $options = array(
      'html' => TRUE,
      'absolute' => !empty($alter['absolute']) ? TRUE : FALSE,
    );

    // $path will be run through check_url() by l() so we do not need to
    // sanitize it ourselves.
    $path = $alter['path'];

    // strip_tags() removes <front>, so check whether its different to front.
    if ($path != '<front>') {

      // Use strip tags as there should never be HTML in the path.
      // However, we need to preserve special characters like " that
      // were removed by check_plain().
      $path = strip_tags(decode_entities(strtr($path, $tokens)));
      if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
        $path = $this
          ->caseTransform($path, $this->options['alter']['path_case']);
      }
      if (!empty($alter['replace_spaces'])) {
        $path = str_replace(' ', '-', $path);
      }
    }

    // Parse the URL and move any query and fragment parameters out of the path.
    $url = parse_url($path);

    // Seriously malformed URLs may return FALSE or empty arrays.
    if (empty($url)) {
      return $text;
    }

    // If the path is empty do not build a link around the given text and return
    // it as is.
    // http://www.example.com URLs will not have a $url['path'], so check host as well.
    if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) {
      return $text;
    }

    // If no scheme is provided in the $path, assign the default 'http://'.
    // This allows a url of 'www.example.com' to be converted to 'http://www.example.com'.
    // Only do this on for external URLs.
    if ($alter['external']) {
      if (!isset($url['scheme'])) {

        // There is no scheme, add the default 'http://' to the $path.
        $path = "http://{$path}";

        // Reset the $url array to include the new scheme.
        $url = parse_url($path);
      }
    }
    if (isset($url['query'])) {
      $path = strtr($path, array(
        '?' . $url['query'] => '',
      ));
      $query = drupal_get_query_array($url['query']);

      // Remove query parameters that were assigned a query string replacement
      // token for which there is no value available.
      foreach ($query as $param => $val) {
        if ($val == '%' . $param) {
          unset($query[$param]);
        }
      }
      $options['query'] = $query;
    }
    if (isset($url['fragment'])) {
      $path = strtr($path, array(
        '#' . $url['fragment'] => '',
      ));

      // If the path is empty we want to have a fragment for the current site.
      if ($path == '') {
        $options['external'] = TRUE;
      }
      $options['fragment'] = $url['fragment'];
    }
    $alt = strtr($alter['alt'], $tokens);

    // Set the title attribute of the link only if it improves accessibility
    if ($alt && $alt != $text) {
      $options['attributes']['title'] = decode_entities($alt);
    }
    $class = strtr($alter['link_class'], $tokens);
    if ($class) {
      $options['attributes']['class'] = array(
        $class,
      );
    }
    if (!empty($alter['rel']) && ($rel = strtr($alter['rel'], $tokens))) {
      $options['attributes']['rel'] = $rel;
    }
    $target = check_plain(trim(strtr($alter['target'], $tokens)));
    if (!empty($target)) {
      $options['attributes']['target'] = $target;
    }

    // Allow the addition of arbitrary attributes to links. Additional attributes
    // currently can only be altered in preprocessors and not within the UI.
    if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) {
      foreach ($alter['link_attributes'] as $key => $attribute) {
        if (!isset($options['attributes'][$key])) {
          $options['attributes'][$key] = strtr($attribute, $tokens);
        }
      }
    }

    // If the query and fragment were programatically assigned overwrite any
    // parsed values.
    if (isset($alter['query'])) {

      // Convert the query to a string, perform token replacement, and then
      // convert back to an array form for l().
      $options['query'] = drupal_http_build_query($alter['query']);
      $options['query'] = strtr($options['query'], $tokens);
      $options['query'] = drupal_get_query_array($options['query']);
    }
    if (isset($alter['alias'])) {

      // Alias is a boolean field, so no token.
      $options['alias'] = $alter['alias'];
    }
    if (isset($alter['fragment'])) {
      $options['fragment'] = strtr($alter['fragment'], $tokens);
    }
    if (isset($alter['language'])) {
      $options['language'] = $alter['language'];
    }

    // If the url came from entity_uri(), pass along the required options.
    if (isset($alter['entity'])) {
      $options['entity'] = $alter['entity'];
    }
    if (isset($alter['entity_type'])) {
      $options['entity_type'] = $alter['entity_type'];
    }
    $value .= l($text, $path, $options);
    if (!empty($alter['suffix'])) {
      $value .= filter_xss_admin(strtr($alter['suffix'], $tokens));
    }
    return $value;
  }

  /**
   * Get the 'render' tokens to use for advanced rendering.
   *
   * This runs through all of the fields and arguments that
   * are available and gets their values. This will then be
   * used in one giant str_replace().
   */
  function get_render_tokens($item) {
    $tokens = array();
    if (!empty($this->view->build_info['substitutions'])) {
      $tokens = $this->view->build_info['substitutions'];
    }
    $count = 0;
    foreach ($this->view->display_handler
      ->getHandlers('argument') as $arg => $handler) {
      $token = '%' . ++$count;
      if (!isset($tokens[$token])) {
        $tokens[$token] = '';
      }

      // Use strip tags as there should never be HTML in the path.
      // However, we need to preserve special characters like " that
      // were removed by check_plain().
      $tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
    }

    // Get flattened set of tokens for any array depth in $_GET parameters.
    $tokens += $this
      ->get_token_values_recursive(drupal_container()
      ->get('request')->query
      ->all());

    // Now add replacements for our fields.
    foreach ($this->view->display_handler
      ->getHandlers('field') as $field => $handler) {
      if (isset($handler->last_render)) {
        $tokens["[{$field}]"] = $handler->last_render;
      }
      else {
        $tokens["[{$field}]"] = '';
      }
      if (!empty($item)) {
        $this
          ->add_self_tokens($tokens, $item);
      }

      // We only use fields up to (and including) this one.
      if ($field == $this->options['id']) {
        break;
      }
    }

    // Store the tokens for the row so we can reference them later if necessary.
    $this->view->style_plugin->render_tokens[$this->view->row_index] = $tokens;
    $this->last_tokens = $tokens;
    return $tokens;
  }

  /**
   * Recursive function to add replacements for nested query string parameters.
   *
   * E.g. if you pass in the following array:
   *   array(
   *     'foo' => array(
   *       'a' => 'value',
   *       'b' => 'value',
   *     ),
   *     'bar' => array(
   *       'a' => 'value',
   *       'b' => array(
   *         'c' => value,
   *       ),
   *     ),
   *   );
   *
   * Would yield the following array of tokens:
   *   array(
   *     '%foo_a' => 'value'
   *     '%foo_b' => 'value'
   *     '%bar_a' => 'value'
   *     '%bar_b_c' => 'value'
   *   );
   *
   * @param $array
   *   An array of values.
   *
   * @param $parent_keys
   *   An array of parent keys. This will represent the array depth.
   *
   * @return
   *   An array of available tokens, with nested keys representative of the array structure.
   */
  function get_token_values_recursive(array $array, array $parent_keys = array()) {
    $tokens = array();
    foreach ($array as $param => $val) {
      if (is_array($val)) {

        // Copy parent_keys array, so we don't affect other elements of this
        // iteration.
        $child_parent_keys = $parent_keys;
        $child_parent_keys[] = $param;

        // Get the child tokens.
        $child_tokens = $this
          ->get_token_values_recursive($val, $child_parent_keys);

        // Add them to the current tokens array.
        $tokens += $child_tokens;
      }
      else {

        // Create a token key based on array element structure.
        $token_string = !empty($parent_keys) ? implode('_', $parent_keys) . '_' . $param : $param;
        $tokens['%' . $token_string] = strip_tags(decode_entities($val));
      }
    }
    return $tokens;
  }

  /**
   * Add any special tokens this field might use for itself.
   *
   * This method is intended to be overridden by items that generate
   * fields as a list. For example, the field that displays all terms
   * on a node might have tokens for the tid and the term.
   *
   * By convention, tokens should follow the format of [token-subtoken]
   * where token is the field ID and subtoken is the field. If the
   * field ID is terms, then the tokens might be [terms-tid] and [terms-name].
   */
  function add_self_tokens(&$tokens, $item) {
  }

  /**
   * Document any special tokens this field might use for itself.
   *
   * @see add_self_tokens()
   */
  function document_self_tokens(&$tokens) {
  }

  /**
   * Call out to the theme() function, which probably just calls render() but
   * allows sites to override output fairly easily.
   */
  function theme($values) {
    return theme($this
      ->themeFunctions(), array(
      'view' => $this->view,
      'field' => $this,
      'row' => $values,
    ));
  }
  public function themeFunctions() {
    $themes = array();
    $hook = 'views_view_field';
    $display = $this->view->display_handler->display;
    if (!empty($display)) {
      $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['id'] . '__' . $this->options['id'];
      $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['id'];
      $themes[] = $hook . '__' . $display['id'] . '__' . $this->options['id'];
      $themes[] = $hook . '__' . $display['id'];
      if ($display['id'] != $display['display_plugin']) {
        $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['display_plugin'] . '__' . $this->options['id'];
        $themes[] = $hook . '__' . $this->view->storage->name . '__' . $display['display_plugin'];
        $themes[] = $hook . '__' . $display['display_plugin'] . '__' . $this->options['id'];
        $themes[] = $hook . '__' . $display['display_plugin'];
      }
    }
    $themes[] = $hook . '__' . $this->view->storage->name . '__' . $this->options['id'];
    $themes[] = $hook . '__' . $this->view->storage->name;
    $themes[] = $hook . '__' . $this->options['id'];
    $themes[] = $hook;
    return $themes;
  }
  public function adminLabel($short = FALSE) {
    return $this
      ->getField(parent::adminLabel($short));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldPluginBase::$additional_fields property Stores additional fields which get's added to the query. The generated aliases are stored in $aliases.
FieldPluginBase::$aliases property
FieldPluginBase::$field_alias property
FieldPluginBase::$original_value public property The field value prior to any rewriting.
FieldPluginBase::add_additional_fields function Add 'additional' fields to the query.
FieldPluginBase::add_self_tokens function Add any special tokens this field might use for itself. 4
FieldPluginBase::adminLabel public function Return a string representing this handler's name in the UI. Overrides HandlerBase::adminLabel 1
FieldPluginBase::adminSummary public function Provide extra data to the administration form Overrides HandlerBase::adminSummary
FieldPluginBase::advanced_render function Render a field using advanced settings.
FieldPluginBase::allow_advanced_render function Determine if this field can allow advanced rendering. 1
FieldPluginBase::buildOptionsForm public function Default options form that provides the label widget that all fields should have. Overrides HandlerBase::buildOptionsForm 32
FieldPluginBase::click_sort function Called to determine what to tell the clicksorter. 1
FieldPluginBase::click_sortable function Determine if this field is click sortable. 1
FieldPluginBase::defineOptions protected function Information about options for all kinds of purposes will be held here. @code 'option_name' => array( Overrides HandlerBase::defineOptions 33
FieldPluginBase::document_self_tokens function Document any special tokens this field might use for itself. 3
FieldPluginBase::element_classes function Return the class of the field.
FieldPluginBase::element_label_classes function Return the class of the field's label.
FieldPluginBase::element_label_type function Return an HTML element for the label based upon the field's element type.
FieldPluginBase::element_type function Return an HTML element based upon the field's element type. 2
FieldPluginBase::element_wrapper_classes function Return the class of the field's wrapper.
FieldPluginBase::element_wrapper_type function Return an HTML element for the wrapper based upon the field's element type.
FieldPluginBase::get_elements function Provide a list of elements valid for field HTML.
FieldPluginBase::get_entity function Get the entity matching the current row and relationship.
FieldPluginBase::get_render_tokens function Get the 'render' tokens to use for advanced rendering.
FieldPluginBase::get_token_values_recursive function Recursive function to add replacements for nested query string parameters.
FieldPluginBase::get_value function Get the value that's supposed to be rendered. 1
FieldPluginBase::init public function Overrides Drupal\views\Plugin\views\HandlerBase::init(). Overrides HandlerBase::init 25
FieldPluginBase::is_value_empty function Checks if a field value is empty.
FieldPluginBase::label public function Get this field's label.
FieldPluginBase::pre_render function Run before any fields are rendered. 6
FieldPluginBase::query public function Called to add the field to a query. Overrides PluginBase::query 22
FieldPluginBase::render function Render the field. 39
FieldPluginBase::render_altered function Render this field as altered text, from a fieldset set by the user.
FieldPluginBase::render_as_link function Render this field as a link, with the info from a fieldset set by the user.
FieldPluginBase::render_text function Perform an advanced text render for the item.
FieldPluginBase::render_trim_text function Trim the field down to the specified length.
FieldPluginBase::submitOptionsForm public function Performs some cleanup tasks on the options array before saving it. Overrides HandlerBase::submitOptionsForm
FieldPluginBase::theme function Call out to the theme() function, which probably just calls render() but allows sites to override output fairly easily.
FieldPluginBase::themeFunctions public function Provide a full list of possible theme templates used by this style. Overrides PluginBase::themeFunctions
FieldPluginBase::tokenize_value function Replace a value with tokens from the last field.
FieldPluginBase::use_string_group_by function Determines if this field will be available as an option to group the result by in the style settings.
HandlerBase::$actualField public property When a field has been moved this property is set.
HandlerBase::$actualTable public property When a table has been moved this property is set.
HandlerBase::$field public property With field you can override the realField if the real field is not set.
HandlerBase::$query public property Where the $query object will reside: 1
HandlerBase::$realField public property The actual field in the database table, maybe different on other kind of query plugins/special handlers.
HandlerBase::$relationship public property The relationship used for this field.
HandlerBase::$table public property The table this handler is attached to.
HandlerBase::$tableAlias public property The alias of the table of this handler which is used in the query.
HandlerBase::acceptExposedInput public function Take input from exposed handlers and assign to this handler, if necessary. 1
HandlerBase::access public function Check whether current user has access to this handler. 7
HandlerBase::breakPhrase public static function Breaks x,y,z and x+y+z into an array. Numeric only.
HandlerBase::breakPhraseString public static function Breaks x,y,z and x+y+z into an array. Works for strings.
HandlerBase::broken public function Determine if the handler is considered 'broken', meaning it's a a placeholder used when a handler can't be found. 6
HandlerBase::buildExposedForm public function Render our chunk of the exposed handler form when selecting 1
HandlerBase::buildExposeForm public function Form for exposed handler options. 2
HandlerBase::buildExtraOptionsForm public function Provide a form for setting options. 1
HandlerBase::buildGroupByForm public function Provide a form for aggregation settings. 1
HandlerBase::canExpose public function Determine if a handler can be exposed. 2
HandlerBase::caseTransform protected function Transform a string by a certain method.
HandlerBase::defaultExposeOptions public function Set new exposed option defaults when exposed setting is flipped on. 2
HandlerBase::defineExtraOptions public function Provide defaults for the handler.
HandlerBase::ensureMyTable public function Ensure the main table for this handler is in the query. This is used a lot. 8
HandlerBase::exposedInfo public function Get information about the exposed form for the form renderer. 1
HandlerBase::getField public function Shortcut to get a handler's raw field value.
HandlerBase::getJoin public function Get the join object that should be used for this handler.
HandlerBase::getSQLDateField public function Creates cross-database SQL dates.
HandlerBase::getSQLFormat public function Creates cross-database SQL date formatting.
HandlerBase::getTableJoin public static function Fetches a handler to join one table to a primary table from the data cache.
HandlerBase::getTimezone public static function Figure out what timezone we're in; needed for some date manipulations.
HandlerBase::hasExtraOptions public function If a handler has 'extra options' it will get a little settings widget and another form called extra_options. 1
HandlerBase::isAGroup public function Returns TRUE if the exposed filter works like a grouped filter. 1
HandlerBase::isExposed public function Determine if this item is 'exposed', meaning it provides form elements to let users modify the view.
HandlerBase::multipleExposedInput public function Define if the exposed input has to be submitted multiple times. This is TRUE when exposed filters grouped are using checkboxes as widgets. 1
HandlerBase::placeholder protected function Provides a unique placeholders for handlers.
HandlerBase::postExecute public function Run after the view is executed, before the result is cached.
HandlerBase::preQuery public function Run before the view is built. 1
HandlerBase::sanitizeValue protected function Sanitize the value for output.
HandlerBase::setRelationship public function Called just prior to query(), this lets a handler set up any relationship it needs.
HandlerBase::showExposeButton public function Shortcut to display the expose/hide button. 2
HandlerBase::showExposeForm public function Shortcut to display the exposed options form.
HandlerBase::storeExposedInput public function If set to remember exposed input in the session, store it there. 1
HandlerBase::submitExposed public function Submit the exposed handler form
HandlerBase::submitExposeForm public function Perform any necessary changes to the form exposes prior to storage. There is no need for this function to actually store the data.
HandlerBase::submitExtraOptionsForm public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.
HandlerBase::submitGroupByForm public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. 1
HandlerBase::usesGroupBy public function Provides the handler some groupby. 2
HandlerBase::validate public function Validates the handler against the complete View. Overrides PluginBase::validate 1
HandlerBase::validateExposed public function Validate the exposed handler form 4
HandlerBase::validateExposeForm public function Validate the options form. 1
HandlerBase::validateExtraOptionsForm public function Validate the options form.
HandlerBase::validateOptionsForm public function Validate the options form. Overrides PluginBase::validateOptionsForm 4
HandlerBase::__construct public function Constructs a Handler object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$definition public property Plugins's definition
PluginBase::$displayHandler public property The display object this plugin is for.
PluginBase::$options public property Options for this plugin will be held here.
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::$usesOptions protected property Denotes whether the plugin has an additional options form. 8
PluginBase::$view public property The top object of a view. 1
PluginBase::additionalThemeFunctions public function Provide a list of additional theme functions for the theme information page
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::destroy public function Clears a plugin. 2
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginBase::pluginTitle public function Return the human readable name of the display.
PluginBase::setOptionDefaults protected function
PluginBase::summaryTitle public function Returns the summary of the settings in the display. 6
PluginBase::unpackOptions public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
PluginBase::usesOptions public function Returns the usesOptions property. 8