Commit e3d6b873 authored by tim.plunkett's avatar tim.plunkett

Remove procedural code from plugins.

parent 0bd39a76
......@@ -49,15 +49,3 @@ function render($values) {
return $this->options['alter']['text'];
}
}
/**
* Prerender function to move the textarea to the top.
*/
function views_handler_field_custom_pre_render_move_text($form) {
$form['text'] = $form['alter']['text'];
$form['help'] = $form['alter']['help'];
unset($form['alter']['text']);
unset($form['alter']['help']);
return $form;
}
......@@ -1209,8 +1209,8 @@ function compile_fields($fields_array, $query) {
if (!empty($field['function'])) {
$info = $this->get_aggregation_info();
if (!empty($info[$field['function']]['method']) && function_exists($info[$field['function']]['method'])) {
$string = $info[$field['function']]['method']($field['function'], $string);
if (!empty($info[$field['function']]['method']) && is_callable(array($this, $info[$field['function']]['method']))) {
$string = $this::$info[$field['function']]['method']($field['function'], $string);
$placeholders = !empty($field['placeholders']) ? $field['placeholders'] : array();
$query->addExpression($string, $fieldname, $placeholders);
}
......@@ -1537,7 +1537,7 @@ function get_aggregation_info() {
),
'count' => array(
'title' => t('Count'),
'method' => 'views_query_default_aggregation_method_simple',
'method' => 'aggregation_method_simple',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1547,7 +1547,7 @@ function get_aggregation_info() {
),
'count_distinct' => array(
'title' => t('Count DISTINCT'),
'method' => 'views_query_default_aggregation_method_distinct',
'method' => 'aggregation_method_distinct',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1557,7 +1557,7 @@ function get_aggregation_info() {
),
'sum' => array(
'title' => t('Sum'),
'method' => 'views_query_default_aggregation_method_simple',
'method' => 'aggregation_method_simple',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1567,7 +1567,7 @@ function get_aggregation_info() {
),
'avg' => array(
'title' => t('Average'),
'method' => 'views_query_default_aggregation_method_simple',
'method' => 'aggregation_method_simple',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1577,7 +1577,7 @@ function get_aggregation_info() {
),
'min' => array(
'title' => t('Minimum'),
'method' => 'views_query_default_aggregation_method_simple',
'method' => 'aggregation_method_simple',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1587,7 +1587,7 @@ function get_aggregation_info() {
),
'max' => array(
'title' => t('Maximum'),
'method' => 'views_query_default_aggregation_method_simple',
'method' => 'aggregation_method_simple',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1597,7 +1597,7 @@ function get_aggregation_info() {
),
'stddev_pop' => array(
'title' => t('Standard derivation'),
'method' => 'views_query_default_aggregation_method_simple',
'method' => 'aggregation_method_simple',
'handler' => array(
'argument' => 'groupby_numeric',
'field' => 'groupby_numeric',
......@@ -1651,27 +1651,14 @@ function get_result_entities($results, $relationship = NULL) {
}
return array($entity_type, $result);
}
}
function views_query_default_aggregation_method_simple($group_type, $field) {
return strtoupper($group_type) . '(' . $field . ')';
}
function views_query_default_aggregation_method_distinct($group_type, $field) {
$group_type = str_replace('_distinct', '', $group_type);
return strtoupper($group_type) . '(DISTINCT ' . $field . ')';
}
function aggregation_method_simple($group_type, $field) {
return strtoupper($group_type) . '(' . $field . ')';
}
/**
* Validation callback for query tags.
*/
function views_element_validate_tags($element, &$form_state) {
$values = array_map('trim', explode(',', $element['#value']));
foreach ($values as $value) {
if (preg_match("/[^a-z_]/", $value)) {
form_error($element, t('The query tags may only contain lower-case alphabetical characters and underscores.'));
return;
}
function aggregation_method_distinct($group_type, $field) {
$group_type = str_replace('_distinct', '', $group_type);
return strtoupper($group_type) . '(DISTINCT ' . $field . ')';
}
}
}
......@@ -10,33 +10,6 @@
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\Core\Annotation\Plugin;
/**
* Helper function: Return an array of formatter options for a field type.
*
* Borrowed from field_ui.
*/
function _field_view_formatter_options($field_type = NULL) {
$options = &drupal_static(__FUNCTION__);
if (!isset($options)) {
$field_types = field_info_field_types();
$options = array();
foreach (field_info_formatter_types() as $name => $formatter) {
foreach ($formatter['field types'] as $formatter_field_type) {
// Check that the field type exists.
if (isset($field_types[$formatter_field_type])) {
$options[$formatter_field_type][$name] = $formatter['label'];
}
}
}
}
if ($field_type) {
return !empty($options[$field_type]) ? $options[$field_type] : array();
}
return $options;
}
/**
* A field that displays fieldapi fields.
*
......
......@@ -2435,6 +2435,58 @@ function views_process_check_options($element, &$form_state) {
return $element;
}
/**
* Validation callback for query tags.
*/
function views_element_validate_tags($element, &$form_state) {
$values = array_map('trim', explode(',', $element['#value']));
foreach ($values as $value) {
if (preg_match("/[^a-z_]/", $value)) {
form_error($element, t('The query tags may only contain lower-case alphabetical characters and underscores.'));
return;
}
}
}
/**
* Prerender function to move the textarea to the top.
*/
function views_handler_field_custom_pre_render_move_text($form) {
$form['text'] = $form['alter']['text'];
$form['help'] = $form['alter']['help'];
unset($form['alter']['text']);
unset($form['alter']['help']);
return $form;
}
/**
* Helper function: Return an array of formatter options for a field type.
*
* Borrowed from field_ui.
*/
function _field_view_formatter_options($field_type = NULL) {
$options = &drupal_static(__FUNCTION__);
if (!isset($options)) {
$field_types = field_info_field_types();
$options = array();
foreach (field_info_formatter_types() as $name => $formatter) {
foreach ($formatter['field types'] as $formatter_field_type) {
// Check that the field type exists.
if (isset($field_types[$formatter_field_type])) {
$options[$formatter_field_type][$name] = $formatter['label'];
}
}
}
}
if ($field_type) {
return !empty($options[$field_type]) ? $options[$field_type] : array();
}
return $options;
}
/**
* Trim the field down to the specified length.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment