From e3d6b8733a8652c18bc55648475396622a1f94d8 Mon Sep 17 00:00:00 2001
From: Tim Plunkett <git@plnktt.com>
Date: Sat, 11 Aug 2012 21:54:17 -0400
Subject: [PATCH] Remove procedural code from plugins.

---
 .../views/Plugin/views/field/Custom.php       | 12 -----
 lib/Drupal/views/Plugin/views/query/Sql.php   | 45 ++++++----------
 lib/Views/field/Plugin/views/field/Field.php  | 27 ----------
 views.module                                  | 52 +++++++++++++++++++
 4 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/lib/Drupal/views/Plugin/views/field/Custom.php b/lib/Drupal/views/Plugin/views/field/Custom.php
index 838421508909..8cc51b0c216d 100644
--- a/lib/Drupal/views/Plugin/views/field/Custom.php
+++ b/lib/Drupal/views/Plugin/views/field/Custom.php
@@ -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;
-}
diff --git a/lib/Drupal/views/Plugin/views/query/Sql.php b/lib/Drupal/views/Plugin/views/query/Sql.php
index 1a83d0a8f973..4e872d59196a 100644
--- a/lib/Drupal/views/Plugin/views/query/Sql.php
+++ b/lib/Drupal/views/Plugin/views/query/Sql.php
@@ -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 . ')';
   }
-}
 
+}
diff --git a/lib/Views/field/Plugin/views/field/Field.php b/lib/Views/field/Plugin/views/field/Field.php
index e54728693df6..cc17150b24ae 100644
--- a/lib/Views/field/Plugin/views/field/Field.php
+++ b/lib/Views/field/Plugin/views/field/Field.php
@@ -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.
  *
diff --git a/views.module b/views.module
index 056ad2133c7c..762b3b2503cd 100644
--- a/views.module
+++ b/views.module
@@ -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.
  *
-- 
GitLab