Digital Media Insights for Business Owners

Hook_views_api – Use custom db table in Drupal Views – Tutorial

Ok so perhaps you have been in a position where you are developing a specific set of functions for a client in Drupal and you are leaning towards displaying some specific information from the database. It could be in a block or it could be in a page. This information would be displayed perfectly by Views (Drupal module) however you are creating a custom table in your Drupal database and of course Views doesn’t know about it.

You may think that since you are doing custom tables, why not simply bypass Views altogether and create a custom query as well. However, you understand that Views gives you great functionality out of the box like a pager, different display options (blocks, attachments, pages, and sometimes even CSV and more). So you decide that you need to learn how to modify the SQL query. Believe me, you could do that, but it would be a long night. So instead of attempting to change the query directly (which sometimes is inevitable) I am going to share with you how to “present” or “introduce” or “let Views know about” your new custom table so that you can use it for relationships within the GUI.

First let me say that you could do this by utilizing the Data Module. However, you have to enable the Schema Module as well and believe me when it comes to database modules, less is better.


This content is available to subscribers only. Haven't subscribed yet? Do so below:

Register New Account

Say: "Hola" to your new clients.

Follow us on Social Media for more Tips & Tricks.

Other Posts You May Enjoy