Created
January 7, 2016 14:44
-
-
Save matason/7ba6505bcba99d4237b2 to your computer and use it in GitHub Desktop.
POC - Can I include vocabularies from one Drupal site within another?
This file contains 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 | |
/** | |
* The name of the taxonomy central database, usually from $databases | |
* configuration in settings.php | |
*/ | |
define('TAXONOMY_CENTRAL_DATABASE_NAME', 'vocabulary_server'); | |
/** | |
* Controller class for taxonomy central vocabularies. | |
*/ | |
class TaxonomyCentralVocabularyController extends TaxonomyVocabularyController { | |
public function load($ids = array(), $conditions = array()) { | |
db_set_active(TAXONOMY_CENTRAL_DATABASE_NAME); | |
$entities = parent::load($ids, $conditions); | |
db_set_active(); | |
return $entities; | |
} | |
} | |
/** | |
* Implements hook_entity_info(). | |
*/ | |
function taxonomy_central_entity_info() { | |
$info['taxonomy_central_vocabulary'] = array( | |
'label' => t('Taxonomy central vocabulary'), | |
'controller class' => 'TaxonomyCentralVocabularyController', | |
'base table' => 'taxonomy_vocabulary', | |
'entity keys' => array( | |
'id' => 'vid', | |
'label' => 'name', | |
), | |
'fieldable' => FALSE, | |
); | |
return $info; | |
} | |
/** | |
* Implements hook_menu(). | |
*/ | |
function taxonomy_central_menu() { | |
$items['taxonomy-central'] = array( | |
'title' => 'Taxonomy central', | |
'page callback' => 'taxonomy_central_callback', | |
'access arguments' => array('access content'), | |
'type' => MENU_CALLBACK, | |
); | |
return $items; | |
} | |
function taxonomy_central_get_vocabularies() { | |
return taxonomy_central_vocabulary_load_multiple(FALSE, array()); | |
} | |
function taxonomy_central_vocabulary_load_multiple($vids = array(), $conditions = array()) { | |
return entity_load('taxonomy_central_vocabulary', $vids, $conditions); | |
} | |
function taxonomy_central_callback() { | |
var_dump(taxonomy_central_get_vocabularies()); die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment