From 72b17f95b582f54fa631757ff2e65c84cc1ae5be Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Thu, 10 Mar 2016 12:22:40 +0900 Subject: [PATCH] Issue #2662548 by robertwb: Support Plugins for Views Aggregate --- .../views/src/Annotation/ViewsAggregate.php | 85 +++++++++++++++++++ .../views/aggregate/AggregatePluginBase.php | 36 ++++++++ .../views/src/Plugin/views/aggregate/Avg.php | 27 ++++++ .../src/Plugin/views/aggregate/Count.php | 28 ++++++ .../Plugin/views/aggregate/Count_distinct.php | 27 ++++++ .../views/src/Plugin/views/aggregate/Max.php | 27 ++++++ .../src/Plugin/views/aggregate/Median.php | 27 ++++++ .../views/src/Plugin/views/aggregate/Min.php | 27 ++++++ .../src/Plugin/views/aggregate/Stddev_Pop.php | 28 ++++++ .../Plugin/views/aggregate/Stddev_Samp.php | 28 ++++++ .../views/src/Plugin/views/aggregate/Sum.php | 27 ++++++ .../views/src/Plugin/views/query/Sql.php | 78 ++--------------- core/modules/views/views.services.yml | 3 + 13 files changed, 375 insertions(+), 73 deletions(-) create mode 100644 core/modules/views/src/Annotation/ViewsAggregate.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/AggregatePluginBase.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Avg.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Count.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Count_distinct.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Max.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Median.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Min.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Stddev_Pop.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Stddev_Samp.php create mode 100644 core/modules/views/src/Plugin/views/aggregate/Sum.php diff --git a/core/modules/views/src/Annotation/ViewsAggregate.php b/core/modules/views/src/Annotation/ViewsAggregate.php new file mode 100644 index 00000000000..55d702e6cd8 --- /dev/null +++ b/core/modules/views/src/Annotation/ViewsAggregate.php @@ -0,0 +1,85 @@ +getDefinitions(); + asort($plugin_definitions); return array( 'group' => array( 'title' => $this->t('Group results together'), 'is aggregate' => FALSE, ), - 'count' => array( - 'title' => $this->t('Count'), - 'method' => 'aggregationMethodSimple', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ), - 'count_distinct' => array( - 'title' => $this->t('Count DISTINCT'), - 'method' => 'aggregationMethodDistinct', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ), - 'sum' => array( - 'title' => $this->t('Sum'), - 'method' => 'aggregationMethodSimple', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ), - 'avg' => array( - 'title' => $this->t('Average'), - 'method' => 'aggregationMethodSimple', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ), - 'min' => array( - 'title' => $this->t('Minimum'), - 'method' => 'aggregationMethodSimple', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ), - 'max' => array( - 'title' => $this->t('Maximum'), - 'method' => 'aggregationMethodSimple', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ), - 'stddev_pop' => array( - 'title' => $this->t('Standard deviation'), - 'method' => 'aggregationMethodSimple', - 'handler' => array( - 'argument' => 'groupby_numeric', - 'field' => 'numeric', - 'filter' => 'groupby_numeric', - 'sort' => 'groupby_numeric', - ), - ) - ); + ) + $plugin_definitions; } public function aggregationMethodSimple($group_type, $field) { diff --git a/core/modules/views/views.services.yml b/core/modules/views/views.services.yml index 1a01543c674..a01318864ba 100644 --- a/core/modules/views/views.services.yml +++ b/core/modules/views/views.services.yml @@ -56,6 +56,9 @@ services: plugin.manager.views.wizard: class: Drupal\views\Plugin\ViewsPluginManager arguments: [wizard, '@container.namespaces', '@cache.discovery', '@module_handler'] + plugin.manager.views.aggregate: + class: Drupal\views\Plugin\ViewsPluginManager + arguments: [aggregate, '@container.namespaces', '@cache.discovery', '@module_handler'] views.views_data: class: Drupal\views\ViewsData arguments: ['@cache.discovery', '@config.factory', '@module_handler', '@language_manager']