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 1006 additions and 0 deletions
<?php
/**
* @file
* Definition of views_handler_argument_locale_language.
*/
/**
* Argument handler to accept a language.
*
* @ingroup views_argument_handlers
*/
class views_handler_argument_locale_language extends views_handler_argument {
function construct() {
parent::construct('language');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the language.
*/
function summary_name($data) {
return $this->locale_language($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version
* of the language.
*/
function title() {
return $this->locale_language($this->argument);
}
function locale_language($langcode) {
$languages = views_language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
}
}
<?php
/**
* @file
* Definition of views_handler_field_locale_group.
*/
/**
* Field handler to translate a group into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_locale_group extends views_handler_field {
function render($values) {
$groups = module_invoke_all('locale', 'groups');
// Sort the list.
asort($groups);
$value = $this->get_value($values);
return isset($groups[$value]) ? $groups[$value] : '';
}
}
<?php
/**
* @file
* Definition of views_handler_field_locale_language.
*/
/**
* Field handler to translate a language into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_locale_language extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['native_language'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['native_language'] = array(
'#title' => t('Native language'),
'#type' => 'checkbox',
'#default_value' => $this->options['native_language'],
'#description' => t('If enabled, the native name of the language will be displayed'),
);
}
function render($values) {
$languages = locale_language_list(empty($this->options['native_language']) ? 'name' : 'native');
$value = $this->get_value($values);
return isset($languages[$value]) ? $languages[$value] : '';
}
}
<?php
/**
* @file
* Definition of views_handler_field_locale_link_edit.
*/
/**
* Field handler to present a link to edit a translation.
*
* @ingroup views_field_handlers
*/
class views_handler_field_locale_link_edit extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['lid'] = 'lid';
}
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
parent::options_form($form, $form_state);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function access() {
// Ensure user has access to edit translations.
return user_access('translate interface');
}
function render($values) {
$value = $this->get_value($values, 'lid');
return $this->render_link($this->sanitize_value($value), $values);
}
function render_link($data, $values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'admin/build/translate/edit/' . $data;
$this->options['alter']['query'] = drupal_get_destination();
return $text;
}
}
<?php
/**
* @file
* Definition of views_handler_field_node_language.
*/
/**
* Field handler to translate a language into its readable form.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_language extends views_handler_field_node {
function option_definition() {
$options = parent::option_definition();
$options['native_language'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['native_language'] = array(
'#title' => t('Native language'),
'#type' => 'checkbox',
'#default_value' => $this->options['native_language'],
'#description' => t('If enabled, the native name of the language will be displayed'),
);
}
function render($values) {
$languages = views_language_list(empty($this->options['native_language']) ? 'name' : 'native');
$value = $this->get_value($values);
$value = isset($languages[$value]) ? $languages[$value] : '';
return $this->render_link($value, $values);
}
}
<?php
/**
* @file
* Definition of views_handler_filter_locale_group.
*/
use Drupal\views\Plugins\views\filter\InOperator;
/**
* Filter by locale group.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_locale_group extends InOperator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Group');
$groups = module_invoke_all('locale', 'groups');
// Sort the list.
asort($groups);
$this->value_options = $groups;
}
}
}
<?php
/**
* @file
* Definition of views_handler_filter_locale_language.
*/
use Drupal\views\Plugins\views\filter\InOperator;
/**
* Filter by language.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_locale_language extends InOperator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Language');
$languages = array(
'***CURRENT_LANGUAGE***' => t("Current user's language"),
'***DEFAULT_LANGUAGE***' => t("Default site language"),
LANGUAGE_NOT_SPECIFIED => t('No language')
);
$languages = array_merge($languages, views_language_list());
$this->value_options = $languages;
}
}
}
<?php
/**
* @file
* Definition of views_handler_filter_locale_version.
*/
use Drupal\views\Plugins\views\filter\InOperator;
/**
* Filter by version.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_locale_version extends InOperator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Version');
// Enable filtering by the current installed Drupal version.
$versions = array('***CURRENT_VERSION***' => t('Current installed version'));
$result = db_query('SELECT DISTINCT(version) FROM {locales_source} ORDER BY version');
foreach ($result as $row) {
if (!empty($row->version)) {
$versions[$row->version] = $row->version;
}
}
$this->value_options = $versions;
}
}
}
<?php
/**
* @file
* Definition of views_handler_filter_node_language.
*/
use Drupal\views\Plugins\views\filter\InOperator;
/**
* Filter by language.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_node_language extends InOperator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Language');
$languages = array(
'***CURRENT_LANGUAGE***' => t("Current user's language"),
'***DEFAULT_LANGUAGE***' => t("Default site language"),
LANGUAGE_NOT_SPECIFIED => t('No language')
);
$languages = array_merge($languages, views_language_list());
$this->value_options = $languages;
}
}
}
<?php
/**
* @file
* Handlers for various date arguments.
*
* @ingroup views_argument_handlers
*/
use Drupal\views\Plugins\views\argument\Date;
/**
* Argument handler for a full date (CCYYMMDD)
*/
class views_handler_argument_node_created_fulldate extends Date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->format = 'F j, Y';
$this->arg_format = 'Ymd';
$this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field");
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
}
/**
* Argument handler for a year (CCYY)
*/
class views_handler_argument_node_created_year extends Date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->arg_format = 'Y';
$this->formula = views_date_sql_extract('YEAR', "***table***.$this->real_field");
}
}
/**
* Argument handler for a year plus month (CCYYMM)
*/
class views_handler_argument_node_created_year_month extends Date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->format = 'F Y';
$this->arg_format = 'Ym';
$this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field");
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
}
/**
* Argument handler for a month (MM)
*/
class views_handler_argument_node_created_month extends Date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->formula = views_date_sql_extract('MONTH', "***table***.$this->real_field");
$this->format = 'F';
$this->arg_format = 'm';
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
$month = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
function summary_argument($data) {
// Make sure the argument contains leading zeroes.
return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
}
}
/**
* Argument handler for a day (DD)
*/
class views_handler_argument_node_created_day extends Date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->formula = views_date_sql_extract('DAY', "***table***.$this->real_field");
$this->format = 'j';
$this->arg_format = 'd';
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
// strtotime respects server timezone, so we need to set the time fixed as utc time
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
/**
* Provide a link to the next level of the view
*/
function title() {
$day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}
function summary_argument($data) {
// Make sure the argument contains leading zeroes.
return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
}
}
/**
* Argument handler for a week.
*/
class views_handler_argument_node_created_week extends Date {
/**
* Constructor implementation
*/
function construct() {
parent::construct();
$this->arg_format = 'w';
$this->formula = views_date_sql_extract('WEEK', "***table***.$this->real_field");
}
/**
* Provide a link to the next level of the view
*/
function summary_name($data) {
$created = $data->{$this->name_alias};
return t('Week @week', array('@week' => $created));
}
}
<?php
/**
* @file
* Definition of views_handler_argument_node_language.
*/
/**
* Argument handler to accept a language.
*/
class views_handler_argument_node_language extends views_handler_argument {
function construct() {
parent::construct('language');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the language.
*/
function summary_name($data) {
return $this->node_language($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version of the
* node type.
*/
function title() {
return $this->node_language($this->argument);
}
function node_language($langcode) {
$languages = views_language_list();
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
}
}
<?php
/**
* @file
* Provide node nid argument handler.
*/
/**
* Argument handler to accept a node id.
*/
class views_handler_argument_node_nid extends views_handler_argument_numeric {
/**
* Override the behavior of title(). Get the title of the node.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT n.title FROM {node} n WHERE n.nid IN (:nids)", array(':nids' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}
<?php
/**
* @file
* Definition of views_handler_argument_node_type.
*/
/**
* Argument handler to accept a node type.
*/
class views_handler_argument_node_type extends views_handler_argument_string {
function construct() {
parent::construct('type');
}
/**
* Override the behavior of summary_name(). Get the user friendly version
* of the node type.
*/
function summary_name($data) {
return $this->node_type($data->{$this->name_alias});
}
/**
* Override the behavior of title(). Get the user friendly version of the
* node type.
*/
function title() {
return $this->node_type($this->argument);
}
function node_type($type) {
$output = node_type_get_name($type);
if (empty($output)) {
$output = t('Unknown content type');
}
return check_plain($output);
}
}
<?php
/**
* @file
* Defintion of views_handler_argument_node_uid_revision.
*/
/**
* Filter handler to accept a user id to check for nodes that
* user posted or created a revision on.
*/
class views_handler_argument_node_uid_revision extends views_handler_argument_comment_user_uid {
function query($group_by = FALSE) {
$this->ensure_my_table();
$placeholder = $this->placeholder();
$this->query->add_where_expression(0, "$this->table_alias.uid = $placeholder OR ((SELECT COUNT(*) FROM {node_revision} nr WHERE nr.uid = $placeholder AND nr.nid = $this->table_alias.nid) > 0)", array($placeholder => $this->argument));
}
}
<?php
/**
* @file
* Provide node vid argument handler.
*/
/**
* Argument handler to accept a node revision id.
*/
class views_handler_argument_node_vid extends views_handler_argument_numeric {
// No constructor is necessary.
/**
* Override the behavior of title(). Get the title of the revision.
*/
function title_query() {
$titles = array();
$result = db_query("SELECT n.title FROM {node_revision} n WHERE n.nid IN (:nids)", array(':nids' => $this->value));
foreach ($result as $term) {
$titles[] = check_plain($term->title);
}
return $titles;
}
}
<?php
/**
* @file
* Contains the node from URL argument default plugin.
*/
use Drupal\views\Plugins\views\argument_default\ArgumentDefaultPluginBase;
/**
* Default argument plugin to extract a node via menu_get_object
*
* This plugin actually has no options so it odes not need to do a great deal.
*/
class views_plugin_argument_default_node extends ArgumentDefaultPluginBase {
function get_argument() {
foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i);
if (!empty($node)) {
return $node->nid;
}
}
if (arg(0) == 'node' && is_numeric(arg(1))) {
return arg(1);
}
}
}
<?php
/**
* @file
* Contains the 'node' argument validator plugin.
*/
use Drupal\views\Plugins\views\argument_validator\ArgumentValidatorPluginBase;
/**
* Validate whether an argument is an acceptable node.
*/
class views_plugin_argument_validate_node extends ArgumentValidatorPluginBase {
function option_definition() {
$options = parent::option_definition();
$options['types'] = array('default' => array());
$options['access'] = array('default' => FALSE, 'bool' => TRUE);
$options['access_op'] = array('default' => 'view');
$options['nid_type'] = array('default' => 'nid');
return $options;
}
function options_form(&$form, &$form_state) {
$types = node_type_get_types();
$options = array();
foreach ($types as $type => $info) {
$options[$type] = check_plain(t($info->name));
}
$form['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Content types'),
'#options' => $options,
'#default_value' => $this->options['types'],
'#description' => t('Choose one or more content types to validate with.'),
);
$form['access'] = array(
'#type' => 'checkbox',
'#title' => t('Validate user has access to the content'),
'#default_value' => $this->options['access'],
);
$form['access_op'] = array(
'#type' => 'radios',
'#title' => t('Access operation to check'),
'#options' => array('view' => t('View'), 'update' => t('Edit'), 'delete' => t('Delete')),
'#default_value' => $this->options['access_op'],
'#states' => array(
'visible' => array(
':input[name="options[validate][options][node][access]"]' => array('checked' => TRUE),
),
),
);
$form['nid_type'] = array(
'#type' => 'select',
'#title' => t('Filter value format'),
'#options' => array(
'nid' => t('Node ID'),
'nids' => t('Node IDs separated by , or +'),
),
'#default_value' => $this->options['nid_type'],
);
}
function options_submit(&$form, &$form_state, &$options = array()) {
// filter trash out of the options so we don't store giant unnecessary arrays
$options['types'] = array_filter($options['types']);
}
function convert_options(&$options) {
if (!isset($options['types']) && !empty($this->argument->options['validate_argument_node_type'])) {
$options['types'] = isset($this->argument->options['validate_argument_node_type']) ? $this->argument->options['validate_argument_node_type'] : array();
$options['access'] = !empty($this->argument->options['validate_argument_node_access']);
$options['access_op'] = isset($this->argument->options['validate_argument_node_access_op']) ? $this->argument->options['validate_argument_node_access_op'] : 'view';
$options['nid_type'] = isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : array();
}
}
function validate_argument($argument) {
$types = $this->options['types'];
switch ($this->options['nid_type']) {
case 'nid':
if (!is_numeric($argument)) {
return FALSE;
}
$node = node_load($argument);
if (!$node) {
return FALSE;
}
if (!empty($this->options['access'])) {
if (!node_access($this->options['access_op'], $node)) {
return FALSE;
}
}
// Save the title() handlers some work.
$this->argument->validated_title = check_plain($node->title);
if (empty($types)) {
return TRUE;
}
return isset($types[$node->type]);
break;
case 'nids':
$nids = new stdClass();
$nids->value = array($argument);
$nids = views_break_phrase($argument, $nids);
if ($nids->value == array(-1)) {
return FALSE;
}
$test = drupal_map_assoc($nids->value);
$titles = array();
$result = db_query("SELECT * FROM {node} WHERE nid IN (:nids)", array(':nids' => $nids->value));
foreach ($result as $node) {
if ($types && empty($types[$node->type])) {
return FALSE;
}
if (!empty($this->options['access'])) {
if (!node_access($this->options['access_op'], $node)) {
return FALSE;
}
}
$titles[] = check_plain($node->title);
unset($test[$node->nid]);
}
$this->argument->validated_title = implode($nids->operator == 'or' ? ' + ' : ', ', $titles);
// If this is not empty, we did not find a nid.
return empty($test);
}
}
}
<?php
/**
* @file
* Definition of views_handler_field_history_user_timestamp.
*/
/**
* Field handler to display the marker for new content.
*
* The handler is named history_user, because of compability reasons, the table
* is history.
*
* @ingroup views_field_handlers
*/
class views_handler_field_history_user_timestamp extends views_handler_field_node {
function init(&$view, &$options) {
parent::init($view, $options);
global $user;
if ($user->uid) {
$this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
$this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
if (module_exists('comment') && !empty($this->options['comments'])) {
$this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
}
}
}
function option_definition() {
$options = parent::option_definition();
$options['comments'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
if (module_exists('comment')) {
$form['comments'] = array(
'#type' => 'checkbox',
'#title' => t('Check for new comments as well'),
'#default_value' => !empty($this->options['comments']),
'#fieldset' => 'more',
);
}
}
function query() {
// Only add ourselves to the query if logged in.
global $user;
if (!$user->uid) {
return;
}
parent::query();
}
function render($values) {
// Let's default to 'read' state.
// This code shadows node_mark, but it reads from the db directly and
// we already have that info.
$mark = MARK_READ;
global $user;
if ($user->uid) {
$last_read = $this->get_value($values);
$created = $this->get_value($values, 'created');
$changed = $this->get_value($values, 'changed');
$last_comment = module_exists('comment') && !empty($this->options['comments']) ? $this->get_value($values, 'last_comment') : 0;
if (!$last_read && $created > NODE_NEW_LIMIT) {
$mark = MARK_NEW;
}
elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
$mark = MARK_UPDATED;
}
elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
$mark = MARK_UPDATED;
}
return $this->render_link(theme('mark', array('type' => $mark)), $values);
}
}
}
<?php
/**
* @file
* Contains the basic 'node' field handler.
*/
use Drupal\views\Plugins\views\field\FieldPluginBase;
/**
* Field handler to provide simple renderer that allows linking to a node.
* Definition terms:
* - link_to_node default: Should this field have the checkbox "link to node" enabled by default.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node extends FieldPluginBase {
function init(&$view, &$options) {
parent::init($view, $options);
// Don't add the additional fields to groupby
if (!empty($this->options['link_to_node'])) {
$this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid');
if (module_exists('translation')) {
$this->additional_fields['language'] = array('table' => 'node', 'field' => 'language');
}
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_node'] = array('default' => isset($this->definition['link_to_node default']) ? $this->definition['link_to_node default'] : FALSE, 'bool' => TRUE);
return $options;
}
/**
* Provide link to node option
*/
function options_form(&$form, &$form_state) {
$form['link_to_node'] = array(
'#title' => t('Link this field to the original piece of content'),
'#description' => t("Enable to override this field's links."),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_node']),
);
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_node']) && !empty($this->additional_fields['nid'])) {
if ($data !== NULL && $data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/" . $this->get_value($values, 'nid');
if (isset($this->aliases['language'])) {
$languages = language_list();
$language = $this->get_value($values, 'language');
if (isset($languages[$language])) {
$this->options['alter']['language'] = $languages[$language];
}
else {
unset($this->options['alter']['language']);
}
}
}
else {
$this->options['alter']['make_link'] = FALSE;
}
}
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_node_link.
*/
/**
* Field handler to present a link to the node.
*
* @ingroup views_field_handlers
*/
class views_handler_field_node_link extends views_handler_field_entity {
function option_definition() {
$options = parent::option_definition();
$options['text'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
parent::options_form($form, $form_state);
// The path is set by render_link function so don't allow to set it.
$form['alter']['path'] = array('#access' => FALSE);
$form['alter']['external'] = array('#access' => FALSE);
}
function render($values) {
if ($entity = $this->get_value($values)) {
return $this->render_link($entity, $values);
}
}
function render_link($node, $values) {
if (node_access('view', $node)) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "node/$node->nid";
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
return $text;
}
}
}
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