Back in the good old Drupal 6 days, if you ever had to integrate a generic SQL table with Views you would use Table Wizard. You could write custom code, but Table Wizard made it very easy to integrate tables without writing any code.
Once you have SQL tables exposed to Views a whole world of possibilities opens up. You can have “non-technical” site builders create complex queries using data from tables by simply creating a view. Currently there is no Drupal 7 version of Table Wizard because it was deprecated in favour of the Data module. The Data module offers more than just Views integration, but in this article we’ll focus on the Views integration part only.
We’ll also have a quick look at two modules called Schema Views and Views Schema, both allow you to integrate Schema API defined tables with Views, but in two different ways. It’s important to note that Schema Views and Views Schema module only allow you to integrate tables that have been defined using Drupal’s Schema API.
How to Use the Data Module
As stated earlier, the Data module does a lot more than just Views integration. It offers a set of low level APIs that help you manage SQL tables and data within those tables. If you want to find out more about the Data module check out the project page.
Integrate Table using Data Module
1. Download and enable the Schema module.
2. Download the Data module and enable the Data and “Data Admin UI” module.
3. Go to Structure -> “Data tables” (admin/structure/data) and click on the “Adopt tables” tab.
Any tables that have been created manually by using phpMyAdmin or any other way should appear on this page.
4. Select the table and click on Adopt.
5. Once the table has been adopted if should appear on the Overview page.
6. If you now create a view, the table should appear within the Show drop-down list on the “Add new view” page.
How to Use the Schema based Modules
Using Schema Views
The biggest difference between the two modules is that Schema Views generates scaffolding code that you must paste into a custom module.
I believe this method gives you the most flexibility, because you have full control over the code. Use the module to generate the boiler plate code and then modify it as required. Once you have copied the code you can uninstall the module as it’s no longer need.
The Schema Views configuration can be accessed by going to Structure -> Schema and click on the Views tab (admin/structure/schema/views).
Using Views Schema
The Views Schema module works slightly differently. It integrates Schema API defined tables at runtime using the
hook_views_data hook. This has the benefit of not having to deal with custom modules and code so it’s a better solution for non developers.
The Views Schema configuration page can be accessed by going to Structure -> Views and click on “Views Schema modules” tab.
Select the tables you want and click on “Save configuration”.
If you go to the “Add new view” page, you should see the selected table within the Show drop-down list.
If you have any questions, please leave a comment.