1

How can I create a view that's based on a custom table from a custom module.

Actually in creating views path I can see options of view types as:

View type:

Node: Nodes are a Drupal site's primary content.

Comment: Comments are responses to node content.

File: Files maintained by Drupal and various modules.

Node revision: Node revisions are a history of changes to nodes.

Term: Taxonomy terms are attached to nodes.

User: Users who have created accounts on your site.

But when selecting the node option I can only select from node table and selecting user I can select from the user table for displaying the data from these tables. But if I need to display data from the custom tables how can I select that table on creating the query and display them on the view pages?

enter image description here

1 Answer 1

1

You need to implement hook_views_data to tell Views about your tables and how the data in your tables relates to other tables defined to Views (if it does). Here's a good tutorial to get you started: http://www.grasmash.com/article/demystifying-views-api-developers-guide-integrating-views

Depending on the nature of your data, you may, alternatively, consider defining your custom data as a custom entity type. If you do that through the Entity API module, then it will provide Views integration "for free".

7
  • How it differ from the hook_theme system ?
    – KTM
    Commented Aug 11, 2015 at 16:44
  • It's similar only in that they're both hooks. hook_theme is a completely separate hook which does totally separate things.
    – Aaron
    Commented Aug 11, 2015 at 16:45
  • There is MODULENAME.views.inc and i can send the data processed through hook_views_data() function , but how clearly it handles the html view files ? or how can i show data in html files
    – KTM
    Commented Aug 12, 2015 at 9:10
  • Is there any view.tpl.php file specific to a module function ?
    – KTM
    Commented Aug 12, 2015 at 15:41
  • Views tpl suggestions are determined based on a number of factors including the name of the view, name of the display, display plugin used, and a variety of other things. If you want to provide a general way to customize the look of a view you need to write a display plugin. If you want to override the look of a specific view then your theme can implement an appropriately-named tpl. I'm confused, though, because none of this has anything to do with exposing your custom tables to Views.
    – Aaron
    Commented Aug 12, 2015 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.