Views for Developers – Live Blogging from Drupal Camp NYC 8

By: Frank Carey

Question: How to integrate your custom module with all the goodie-ness of views?

Shameless Plug: I attempted to write a similar post about this in this post: Views Integration with your custom module and Overwriting Views Handlers

The custom way to integrate your module is by using hook_views_data. Using this hook, you would define how your module exposes data to views. A great alternative is using the Table Wizard module.

Example: Create Custom Watchdog View using Table Wizard

(Following list is not an actual “step by step” list, but the general idea is that Table Wizard allows us to create the array required for hook_views_data in a much simpler way than coding it by hand).

  • Select “Add existing tables”
  • Select the table you want to expose
  • Select “Provide default View”
  • Create a new table wizard entry for users
  • Create a relationship bewteen the two using the relationship and join on uid (users.uid joins with watchdog.uid)
    Options here are manual or automatic (manual: relationship needs to be added manually in the view, automatic: happens in the background without option in views interface)
  • Select the new table wizard entry that was just created and then export the views definition for it