Exposing Tables to Views in Drupal 7

Posted by Unknown on Monday, June 9, 2014

In this article you are going to learn how to expose the table created by your Drupal module to Views. Why would you like to do this? Views is a powerful module for querying and displaying information and can save you a lot of hassle when dealing with the custom data your module produces.


The focus of this tutorial will be on data that is not abstracted as Drupal entities, but simply stored in a table. Exposing custom entities to Views is a topic I covered in another Sitepoint.com series so I recommend reading up on that if this is the case for you - here is a list of my articles.


I set up a module called expose in this repository that you can clone, follow along and even build on if you want to learn more. The master branch contains a clean module that simply creates the table I will use in this article to illustrate the process. The exposed-table branch contains, commit by commit, the steps I go through below.


Since the schema definition is in the module, I will not repeat it here. I will however give you a short MySQL command to generate a couple of dummy records to have something to play with. Hopefully this command is informative enough to describe the table structure as well:



INSERT INTO `exposed` (`id`, `name`, `deadline`, `node_id`)
VALUES
(1, 'Danny', 1399477939, 1),
(2, 'Peter', 1399477957, 2);


Continue reading %Exposing Tables to Views in Drupal 7%




more

{ 0 comments... » Exposing Tables to Views in Drupal 7 read them below or add one }

Post a Comment

Popular Posts