Last active
December 15, 2015 23:59
-
-
Save fago/5344570 to your computer and use it in GitHub Desktop.
Entity storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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