Skip to content

Instantly share code, notes, and snippets.

@matason
Created January 7, 2016 14:44
Show Gist options
  • Save matason/7ba6505bcba99d4237b2 to your computer and use it in GitHub Desktop.
Save matason/7ba6505bcba99d4237b2 to your computer and use it in GitHub Desktop.
POC - Can I include vocabularies from one Drupal site within another?
<?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