You are here

class views_handler_field_ym_title in Yandex.Metrics 6.2

Same name and namespace in other branches
  1. 8.2 yandex_metrics_reports/views/handlers/views_handler_field_ym_title.inc \views_handler_field_ym_title
  2. 7.2 yandex_metrics_reports/views/handlers/views_handler_field_ym_title.inc \views_handler_field_ym_title

Field handler to provide simple renderer that allows linking to a page title. Definition terms:

  • link_to_ym_url default: Should this field have the checkbox "link to url from Yandex.Metricks" enabled by default.

This handler supports Views 2 as well as Views 3.

Hierarchy

Expanded class hierarchy of views_handler_field_ym_title

1 string reference to 'views_handler_field_ym_title'
yandex_metrics_reports_views_data in yandex_metrics_reports/views/yandex_metrics_reports.views.inc
Implements hook_views_data().

File

yandex_metrics_reports/views/handlers/views_handler_field_ym_title.inc, line 16
Contains the basic 'page_title' field handler.

View source
class views_handler_field_ym_title extends views_handler_field {
  function init(&$view, &$options) {
    parent::init($view, $options);

    // Don't add the additional fields to groupby.
    if (!empty($this->options['link_to_ym_url'])) {
      $this->additional_fields['url'] = array(
        'table' => 'yandex_metrics_reports_popular_content',
        'field' => 'url',
      );
    }
  }
  function option_definition() {
    $options = parent::option_definition();
    $options['link_to_ym_url'] = array(
      'default' => isset($this->definition['link_to_ym_url default']) ? $this->definition['link_to_ym_url default'] : FALSE,
      'bool' => TRUE,
    );
    return $options;
  }

  /**
   * Provide link to url.
   */
  function options_form(&$form, &$form_state) {
    $form['link_to_ym_url'] = array(
      '#title' => t('Link this field to URL from Yandex.Metrics'),
      '#description' => t("Enable to override this field's links."),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['link_to_ym_url']),
    );
    parent::options_form($form, $form_state);
  }

  /**
   * Render whatever the data is as a link to the node.
   *
   * Data should be made XSS safe prior to calling this function.
   */
  function render_link($data, $values) {
    if (!empty($this->options['link_to_ym_url']) && !empty($this->additional_fields['url'])) {
      if ($data !== NULL && $data !== '') {
        $this->options['alter']['make_link'] = TRUE;
        $this->options['alter']['path'] = $values->yandex_metrics_reports_popular_content_url;
      }
      else {
        $this->options['alter']['make_link'] = FALSE;
      }
    }
    return $data;
  }
  function render($values) {
    $value = $values->{$this->field_alias};
    return $this
      ->render_link(check_url($value), $values);
  }

}

Members