Changing the Base Table (Entity Type) of a Drupal View

Say you have a view of nodes, and want to change it to another entity, say a custom entity like in my case “dH Feature”.  Of all the settings that can be changed in the Drupal Views Admin UI – the base content type, or base table, cannot.  Once you’ve created your view, you’re stuck with it.  A workaround is to use “Views Export” and “Import”, changing the base table in code.  For my example, I started with a view that:

// Change:
//$view->base_table = ‘node’;
// To:
$view->base_table = ‘dh_feature’;

Et voila!  Now my view can be constructed accordingly.  Caution of course, you have to do a bit more replacing if the fields that you’ve added do not exist in the destination Entity type.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s