Remove procedural code from plugins.

8.0.x
Tim Plunkett 2012-08-11 21:54:17 -04:00
parent 0bd39a76b3
commit e3d6b8733a
4 changed files with 69 additions and 69 deletions

View File

@ -49,15 +49,3 @@ class Custom extends FieldPluginBase {
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;
}

View File

@ -1209,8 +1209,8 @@ class Sql extends QueryPluginBase {
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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
),
'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 @@ class Sql extends QueryPluginBase {
}
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 . ')';
}
/**
* 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_simple($group_type, $field) {
return strtoupper($group_type) . '(' . $field . ')';
}
}
function aggregation_method_distinct($group_type, $field) {
$group_type = str_replace('_distinct', '', $group_type);
return strtoupper($group_type) . '(DISTINCT ' . $field . ')';
}
}

View File

@ -10,33 +10,6 @@ namespace Views\field\Plugin\views\field;
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.
*

View File

@ -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.
*