1

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?

1 Answer 1

1

There is a Field Storage API you can use for external storage in fields.

1
  • I'm trying to avoid writing a whole storage module using Field Storage API. Drupal's default field_sql_storage.module works fine. I just want it to switch to a different database when interacting with my custom field.
    – bendiy
    Commented May 11, 2012 at 20:09

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.