Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / sort / GroupByNumeric.php
diff --git a/web/core/modules/views/src/Plugin/views/sort/GroupByNumeric.php b/web/core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
new file mode 100644 (file)
index 0000000..5308439
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+namespace Drupal\views\Plugin\views\sort;
+
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\ViewExecutable;
+use Drupal\views\Views;
+
+/**
+ * Handler for GROUP BY on simple numeric fields.
+ *
+ * @ViewsSort("groupby_numeric")
+ */
+class GroupByNumeric extends SortPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+    parent::init($view, $display, $options);
+
+    // Initialize the original handler.
+    $this->handler = Views::handlerManager('sort')->getHandler($options);
+    $this->handler->init($view, $display, $options);
+  }
+
+  /**
+   * Called to add the field to a query.
+   */
+  public function query() {
+    $this->ensureMyTable();
+
+    $params = [
+      'function' => $this->options['group_type'],
+    ];
+
+    $this->query->addOrderBy($this->tableAlias, $this->realField, $this->options['order'], NULL, $params);
+  }
+
+  public function adminLabel($short = FALSE) {
+    return $this->getField(parent::adminLabel($short));
+  }
+
+}