Skip to content
Snippets Groups Projects
Commit bd65ce78 authored by Damian Lee's avatar Damian Lee Committed by Tim Plunkett
Browse files

Copied all module handlers to new plugin folder structure

parent d6f0adbb
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 876 additions and 0 deletions
<?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;
}
return $text;
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_link_approve.
*/
/**
* Provides a comment approve link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_approve extends views_handler_field_comment_link {
function access() {
//needs permission to administer comments in general
return user_access('administer comments');
}
function render_link($data, $values) {
$status = $this->get_value($values, 'status');
// Don't show an approve link on published nodes.
if ($status == COMMENT_PUBLISHED) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('approve');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $cid . "/approve";
$this->options['alter']['query'] = drupal_get_destination() + array('token' => drupal_get_token("comment/$cid/approve"));
return $text;
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_link_delete.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_delete extends views_handler_field_comment_link {
function access() {
//needs permission to administer comments in general
return user_access('administer comments');
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/" . $cid . "/delete";
$this->options['alter']['query'] = drupal_get_destination();
return $text;
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_link_edit.
*/
/**
* Field handler to present a link node edit.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_edit extends views_handler_field_comment_link {
function option_definition() {
$options = parent::option_definition();
$options['destination'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['destination'] = array(
'#type' => 'checkbox',
'#title' => t('Use destination'),
'#description' => t('Add destination to the link'),
'#default_value' => $this->options['destination'],
'#fieldset' => 'more',
);
}
function render_link($data, $values) {
parent::render_link($data, $values);
// ensure user has access to edit this comment.
$comment = $this->get_value($values);
if (!comment_access('edit', $comment)) {
return;
}
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
unset($this->options['alter']['fragment']);
if (!empty($this->options['destination'])) {
$this->options['alter']['query'] = drupal_get_destination();
}
$this->options['alter']['path'] = "comment/" . $comment->cid . "/edit";
return $text;
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_link_reply.
*/
/**
* Field handler to present a link to delete a node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_link_reply extends views_handler_field_comment_link {
function access() {
//check for permission to reply to comments
return user_access('post comments');
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('reply');
$nid = $this->get_value($values, 'nid');
$cid = $this->get_value($values, 'cid');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "comment/reply/" . $nid . '/' . $cid;
return $text;
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_node_link.
*/
/**
* Handler for showing comment module's node link.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_node_link extends views_handler_field_entity {
function construct() {
parent::construct();
// Add the node fields that comment_link will need..
$this->additional_fields['nid'] = array(
'field' => 'nid',
);
$this->additional_fields['type'] = array(
'field' => 'type',
);
$this->additional_fields['comment'] = array(
'field' => 'comment',
);
}
function option_definition() {
$options = parent::option_definition();
$options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Show teaser-style link'),
'#default_value' => $this->options['teaser'],
'#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
// Build fake $node.
$node = $this->get_value($values);
// Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
// Call node by reference so that something is changed here
comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
// question: should we run these through: drupal_alter('link', $links, $node);
// might this have unexpected consequences if these hooks expect items in $node that we don't have?
// Only render the links, if they are defined.
return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
}
}
<?php
/**
* @file
* Definition of views_handler_field_comment_username.
*/
/**
* Field handler to allow linking to a user account or homepage.
*
* @ingroup views_field_handlers
*/
class views_handler_field_comment_username extends views_handler_field {
/**
* Override init function to add uid and homepage fields.
*/
function init(&$view, &$data) {
parent::init($view, $data);
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['homepage'] = 'homepage';
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_user'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['link_to_user'] = array(
'#title' => t("Link this field to its user or an author's homepage"),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_user'],
);
parent::options_form($form, $form_state);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_user'])) {
$account = entity_create('user', array());
$account->uid = $this->get_value($values, 'uid');
$account->name = $this->get_value($values);
$account->homepage = $this->get_value($values, 'homepage');
return theme('username', array(
'account' => $account
));
}
else {
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_last_comment_timestamp.
*/
/**
* Field handler to display the timestamp of a comment with the count of comments.
*
* @ingroup views_field_handlers
*/
class views_handler_field_last_comment_timestamp extends views_handler_field_date {
function construct() {
parent::construct();
$this->additional_fields['comment_count'] = 'comment_count';
}
function render($values) {
$comment_count = $this->get_value($values, 'comment_count');
if (empty($this->options['empty_zero']) || $comment_count) {
return parent::render($values);
}
else {
return NULL;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment