I'm interfacing an external database with Drupal 7. I have created custom entities and custom fields to represent the tables in the external database. Is there a simple way to set the fields up so all CRUD uses the external database?
I still want to use Drupal's default field_sql_storage.module, but have it switch to the external database and back for these fields automatically. Can I say "for this field, use this other database".
Something simple like:
function mymodule_field_info() {
return array(
'customfield' => array(
'label' => t('My Custom Field'),
'description' => t('This field stores text in the external database.'),
'settings' => array('max_length' => 255),
'instance_settings' => array('text_processing' => 0),
'default_widget' => 'text_textfield',
'default_formatter' => 'text_default',
// Simple setting to change database.
'database' => 'externaldb', // From settings.php $database connections.
),
}
The hard way is to create a custom storage backend and use it for these fields like the Mongodb module. I've tested this and it works, but it seems like there should be any easier way if you want to use Drupal's default field_sql_storage.module.
Would the strategic placement of db_set_active() allow me to avoid creating a full custom storage backend?