Drupal Views Handler integration with Views Aggregator

05 May
Drupal Views Handler allows you to bring data from other database tables without needing a relationship. In this article we will build a handler that counts a query result that afterwards will be integrated with Views Aggregation to obtain a total.

In order to build a View Handler, first you need to build a custom module. Into the .info file you should add the following.

In the example.module the hook_views_api() must be added.

hook_views_data() must be declared in example.views.inc

Now we can start building the handler example_count_handler.inc

After the handler is built it can be used in whichever View you want to use it in. The handler is added like any other field into the View fields.
Once the handler is added you may need the total of the results counted for each row. The Drupal Views Aggregator can be used for this part.
On the main Views UI page, under Format, instead of Table, click Table with aggregation options. 

Check the Apply column function. In this situation we need the Sum but there are many other possibilities, like Max, Min, Count etc. Also you can decide where you want to place the Total column.

After following the steps mentioned above, you should have something like:


Leave A Comment