1

Is there a way to expose content from other databases to Drupal so Drupal sees them like nodes? Importantly, this should work without making actual node entries in the Drupal database.

This would mean writing a module which specifies how to translate my proprietary content into Drupal node format, so one could write theming functions for that content, or use the Views module on it, etc.

Currently my module just displays the content directly on its own, without bothering to provide seamless Drupal integration into Views.

1 Answer 1

2

It really depends on what you are trying to accomplish.

If you need any Drupal feature, like commenting and tagging, or want to integrate with modules like Fivestar or Flag, then you need a node (or other entity). If you want to get into the theming system, then I think you have no real choice. The way I normally accomplish this is to have a hook that runs hook_node_load, does a call out to the remote system (either REST or direct DB), and then builds up a data structure and sticks it somewhere in $node. You then have some preprocess functions to make the data available to the node templates, or you have a hook_node_view to get the data into the $node->content render array. The next time I need to do this I will likely try to use the Field Storage API with content types defined by hook_node_info.

With this approach, the only thing the node is really used for is to have a $nid / $vid pair available to the rest of Drupal for other modules to work. The content type that you are using typically only needs on field in it to store the primary key in the remote system. I usually also copy over the title to the node to make it easier to identify in the admin UI.

Though all of this may seem hard, it is actually pretty straightforward and mostly easy to implement if you are familiar with the API.

Just remember that what you need to do now may not be what you want to do in the future. Preparing for this by having true nodes available may make better sense in the long run.

1
  • If you want simple Views integration, you can write a custom module to load data from the external database and supply field and style information. The CiviCRM integration is a good working example. svn.civicrm.org/civicrm/trunk/drupal/modules/views .
    – choster
    Apr 5, 2012 at 14:59

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.