Commit bd65ce78 authored by damiankloip's avatar damiankloip Committed by tim.plunkett

Copied all module handlers to new plugin folder structure

parent d6f0adbb
<?php
/**
* @file
* Definition of views_handler_argument_aggregator_category_cid.
*/
use Drupal\views\Plugins\views\argument\Numeric;
/**
* Argument handler to accept an aggregator category id.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_aggregator_category_cid extends Numeric {
/**
* Override the behavior of title(). Get the title of the category.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN (:cid)", array(':cid' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}
<?php
/**
* @file
* Definition of views_handler_argument_aggregator_fid.
*/
use Drupal\views\Plugins\views\argument\Numeric;
/**
* Argument handler to accept an aggregator feed id.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_aggregator_fid extends Numeric {
/**
* Override the behavior of title(). Get the title of the feed.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN (:fids)", array(':fids' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}
<?php
/**
* @file
* Definition of views_handler_argument_aggregator_iid.
*/
use Drupal\views\Plugins\views\argument\Numeric;
/**
* Argument handler to accept an aggregator item id.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_aggregator_iid extends Numeric {
/**
* Override the behavior of title(). Get the title of the category.
*/
function title_query() {
$titles = array();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_select('aggregator_item')
->condition('iid', $this->value, 'IN')
->fields(array('title'))
->execute();
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}
<?php
/**
* @file
* Definition of views_handler_field_aggregator_category.
*/
use Drupal\views\Plugins\views\field\FieldPluginBase;
/**
* Field handler to provide simple renderer that allows linking to aggregator
* category.
*
* @ingroup views_field_handlers
*/
class views_handler_field_aggregator_category extends FieldPluginBase {
/**
* Constructor to provide additional field to add.
*/
function construct() {
parent::construct();
$this->additional_fields['cid'] = 'cid';
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to category option
*/
function options_form(&$form, &$form_state) {
$form['link_to_category'] = array(
'#title' => t('Link this field to its aggregator category page'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_category']),
);
parent::options_form($form, $form_state);
}
/**
* Render whatever the data is as a link to the category.
*
* Data should be made XSS safe prior to calling this function.
*/
function render_link($data, $values) {
$cid = $this->get_value($values, 'cid');
if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "aggregator/category/$cid";
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}
<?php
/**
* @file
* Definition of views_handler_field_aggregator_title_link.
*/
use Drupal\views\Plugins\views\field\FieldPluginBase;
/**
* Field handler that turns an item's title into a clickable link to the original
* source article.
*
* @ingroup views_field_handlers
*/
class views_handler_field_aggregator_title_link extends FieldPluginBase {
function construct() {
parent::construct();
$this->additional_fields['link'] = 'link';
}
function option_definition() {
$options = parent::option_definition();
$options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to the page being visited.
*/
function options_form(&$form, &$form_state) {
$form['display_as_link'] = array(
'#title' => t('Display as link'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['display_as_link']),
);
parent::options_form($form, $form_state);
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
function render_link($data, $values) {
$link = $this->get_value($values, 'link');
if (!empty($this->options['display_as_link'])) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $link;
$this->options['alter']['html'] = TRUE;
}
return $data;
}
}
<?php
/**
* @file
* Definition of views_handler_field_aggregator_xss.
*/
use Drupal\views\Plugins\views\field\FieldPluginBase;
/**
* Filters htmls tags from item.
*
* @ingroup views_field_handlers
*/
class views_handler_field_aggregator_xss extends FieldPluginBase {
function render($values) {
$value = $this->get_value($values);
return aggregator_filter_xss($value);
}
}
<?php
/**
* @file
* Definition of views_handler_filter_aggregator_category_cid.
*/
use Drupal\views\Plugins\views\filter\InOperator;
/**
* Filter by aggregator category cid
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_aggregator_category_cid extends InOperator {
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options = array();
$result = db_query('SELECT * FROM {aggregator_category} ORDER BY title');
foreach ($result as $category) {
$this->value_options[$category->cid] = $category->title;
}
}
}
<?php
/**
* @file
* Contains the Aggregator Item RSS row style plugin.
*/
use Drupal\views\Plugins\views\row\RowPluginBase;
/**
* Plugin which loads an aggregator item and formats it as an RSS item.
*/
class views_plugin_row_aggregator_rss extends RowPluginBase {
var $base_table = 'aggregator_item';
var $base_field = 'iid';
function option_definition() {
$options = parent::option_definition();
$options['item_length'] = array('default' => 'default');
return $options;
}
function options_form(&$form, &$form_state) {
$form['item_length'] = array(
'#type' => 'select',
'#title' => t('Display type'),
'#options' => array(
'fulltext' => t('Full text'),
'teaser' => t('Title plus teaser'),
'title' => t('Title only'),
'default' => t('Use default RSS settings'),
),
'#default_value' => $this->options['item_length'],
);
}
function render($row) {
$iid = $row->{$this->field_alias};
$sql = "SELECT ai.iid, ai.fid, ai.title, ai.link, ai.author, ai.description, ";
$sql .= "ai.timestamp, ai.guid, af.title AS feed_title, ai.link AS feed_LINK ";
$sql .= "FROM {aggregator_item} ai LEFT JOIN {aggregator_feed} af ON ai.fid = af.fid ";
$sql .= "WHERE ai.iid = :iid";
$item = db_query($sql, array(':iid' => $iid))->fetchObject();
$item->elements = array(
array(
'key' => 'pubDate',
'value' => gmdate('r', $item->timestamp),
),
array(
'key' => 'dc:creator',
'value' => $item->author,
),
array(
'key' => 'guid',
'value' => $item->guid,
'attributes' => array('isPermaLink' => 'false')
),
);
foreach ($item->elements as $element) {
if (isset($element['namespace'])) {
$this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']);
}
}
return theme($this->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $item
));
}
}
<?php
/**
* @file
* Contains the book root from current node argument default plugin.
*/
use Drupal\views\Plugins\views\argument_default\Node;
/**
* Default argument plugin to get the current node's book root.
*/
class views_plugin_argument_default_book_root extends Node {
function get_argument() {
// Use the argument_default_node plugin to get the nid argument.
$nid = parent::get_argument();
if (!empty($nid)) {
$node = node_load($nid);
if (isset($node->book['bid'])) {
return $node->book['bid'];
}
}
}
}
<?php
/**
* @file
* Definition of views_handler_argument_comment_user_uid.
*/
/**
* Argument handler to accept a user id to check for nodes that
* user posted or commented on.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_comment_user_uid extends views_handler_argument {
function title() {
if (!$this->argument) {
$title = variable_get('anonymous', t('Anonymous'));
}
else {
$title = db_query('SELECT u.name FROM {users} u WHERE u.uid = :uid', array(':uid' => $this->argument))->fetchField();
}
if (empty($title)) {
return t('No user');
}
return check_plain($title);
}
function default_actions($which = NULL) {
// Disallow summary views on this argument.
if (!$which) {
$actions = parent::default_actions();
unset($actions['summary asc']);
unset($actions['summary desc']);
return $actions;
}
if ($which != 'summary asc' && $which != 'summary desc') {
return parent::default_actions($which);
}
}
function query($group_by = FALSE) {
$this->ensure_my_table();
$subselect = db_select('comment', 'c');
$subselect->addField('c', 'cid');
$subselect->condition('c.uid', $this->argument);
$subselect->where("c.nid = $this->table_alias.nid");
$condition = db_or()
->condition("$this->table_alias.uid", $this->argument, '=')
->exists($subselect);
$this->query->add_where(0, $condition);
}
function get_sort_name() {
return t('Numerical', array(), array('context' => 'Sort order'));
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment.
*/
use Drupal\views\Plugins\views\field\FieldPluginBase;
/**
* Field handler to allow linking to a comment.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment extends FieldPluginBase {
/**
* Override init function to provide generic option to link to comment.
*/
function init(&$view, &$options) {
parent::init($view, $options);
if (!empty($this->options['link_to_comment'])) {
$this->additional_fields['cid'] = 'cid';
$this->additional_fields['nid'] = 'nid';
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_comment'] = array('default' => TRUE, 'bool' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link-to-comment option
*/
function options_form(&$form, &$form_state) {
$form['link_to_comment'] = array(
'#title' => t('Link this field to its comment'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_comment'],
);
$form['link_to_node'] = array(
'#title' => t('Link field to the node if there is no comment.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
parent::options_form($form, $form_state);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_comment'])) {
$this->options['alter']['make_link'] = TRUE;
$nid = $this->get_value($values, 'nid');
$cid = $this->get_value($values, 'cid');
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
else if ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid;
}
}
return $data;
}
function render($values) {
$value = $this->get_value($values);
return $this->render_link($this->sanitize_value($value), $values);
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_depth.
*/
/**
* Field handler to display the depth of a comment.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_depth extends views_handler_field {
/**
* Work out the depth of this comment
*/
function render($values) {
$comment_thread = $this->get_value($values);
return count(explode('.', $comment_thread)) - 1;
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_link.
*/
/**
* Base field handler to present a link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link extends views_handler_field_entity {
function construct() {
parent::construct();
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
$options['link_to_node'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
$form['link_to_node'] = array(
'#title' => t('Link field to the node if there is no comment.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_node'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$value = $this->get_value($values, 'cid');
return $this->render_link($this->sanitize_value($value), $values);
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$comment = $this->get_value($values);
$nid = $comment->nid;
$cid = $comment->cid;
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['html'] = TRUE;
if (!empty($cid)) {
$this->options['alter']['path'] = "comment/" . $cid;
$this->options['alter']['fragment'] = "comment-" . $cid;
}
// If there is no comment link to the node.
else if ($this->options['link_to_node']) {
$this->options['alter']['path'] = "node/" . $nid;