Skip to content

Instantly share code, notes, and snippets.

@fago
Last active December 15, 2015 23:59
Show Gist options
  • Select an option

  • Save fago/5344570 to your computer and use it in GitHub Desktop.

Select an option

Save fago/5344570 to your computer and use it in GitHub Desktop.
Entity storage
<?php
class DatabaseStorageController implements EntityStorageControllerInterface, ExtensibleStorageInterface {
// Helper class implements the ExtensibleStorageInterface + more needed methods like write().
protected $class = 'ExtensibleDBStorageHelper';
protected function getExtensibleStorageHelper() {
...
}
function save() {
// save base fields.
$this->getExtensibleStorageHelper()->write(...);
}
/**
* Implements EntityStorageControllerInterface - forward the calls to the helper.
*
*/
function createExtendedFieldStorage(..) {
// equivalent of http://api.drupal.org/api/drupal/modules!field!field.api.php/function/hook_field_storage_create_field/7
$this->getExtensibleStorageHelper()->createExtendedFieldStorage(..);
}
}
/**
* Converted field API storage
*/
class ExtensibleDBStorageHelper implements ExtensibleStorageInterface {
// Has callbacks as field API storage, thus also implements write().
}
interface ExtensibleStorageInterface {
// Has only the callbacky of field API storage which do not involve entity CRUD, e.g. no write()
}
// Mongo can implement everything in one class if it wants to.
class MongoStorageController implements EntityStorageControllerInterface, ExtensibleStorageInterface {
function save() {
// Store the document in mongo.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment