View source
<?php
function spaces_taxonomy_enable() {
$weight = db_result(db_query("SELECT weight FROM {system} WHERE type = 'module' AND name = 'taxonomy'"));
db_query("UPDATE {system} SET weight = %d WHERE name = 'spaces_taxonomy'", $weight + 1);
}
function spaces_taxonomy_ctools_plugin_api($module, $api) {
if ($module == 'spaces' && $api == 'plugins') {
return array(
'version' => 3,
);
}
}
function spaces_taxonomy_purl_provider() {
$items = array();
$items["spaces_taxonomy"] = array(
'name' => t('Term space'),
'description' => t('Sets a space as the active space.'),
'callback' => 'spaces_init_space',
'callback arguments' => array(
'taxonomy',
),
'example' => 'my-space',
);
return $items;
}
function spaces_taxonomy_spaces_plugins() {
$plugins = array();
$plugins['space_taxonomy'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'spaces_taxonomy') . '/plugins',
'file' => 'space_taxonomy.inc',
'class' => 'space_taxonomy',
'parent' => 'space_type_purl',
),
);
return $plugins;
}
function spaces_taxonomy_spaces_registry() {
return array(
'types' => array(
'taxonomy' => array(
'title' => t('Term space'),
'plugin' => 'space_taxonomy',
'path' => 'taxonomy/term/%',
),
),
);
}
function spaces_taxonomy_menu() {
$items = array();
$items['admin/build/spaces/taxonomy'] = array(
'title' => 'Taxonomy',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'spaces_taxonomy_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer spaces',
),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function spaces_taxonomy_menu_alter(&$items) {
if (isset($items['taxonomy/term/%'])) {
$items['taxonomy/term/%/view'] = $items['taxonomy/term/%'];
$items['taxonomy/term/%/view']['type'] = MENU_DEFAULT_LOCAL_TASK;
$items['taxonomy/term/%/view']['title'] = 'View';
$items['taxonomy/term/%/view']['weight'] = -10;
}
}
function spaces_taxonomy_form_alter(&$form, $form_state, $form_id) {
if ($form['#id'] == 'node-form' && arg(0) . '/' . arg(1) != 'admin/content') {
$vid = variable_get('spaces_taxonomy_vid', 0);
$space = spaces_get_space();
if ($vid && !empty($form['taxonomy'][$vid]) && $space->type == 'taxonomy') {
$form['taxonomy'][$vid]['#disabled'] = TRUE;
$form['taxonomy'][$vid]['#default_value'] = $space->id;
}
}
}
function spaces_taxonomy_form_taxonomy_form_term_alter(&$form, $form_state) {
$vid = variable_get('spaces_taxonomy_vid', 0);
if ($vid && $form['vid']['#value'] == $vid) {
$tid = isset($form['tid']['#value']) ? $form['tid']['#value'] : 0;
$space = spaces_load('taxonomy', $tid);
if ($space) {
$space
->activate();
$form['spaces'] = array(
'#type' => 'fieldset',
'#title' => t('Spaces'),
'#tree' => FALSE,
'#weight' => 0,
);
$modifier = purl_load(array(
'id' => $tid,
'provider' => 'spaces_taxonomy',
));
$form['spaces']['purl'] = purl_form('spaces_taxonomy', $tid, isset($modifier['value']) ? $modifier['value'] : '');
$presets = spaces_preset_load(NULL, 'taxonomy');
if (count($presets) > 1) {
module_load_include('inc', 'spaces', 'spaces.admin');
$form['spaces']['spaces_preset'] = spaces_preset_form($presets, 'taxonomy');
$space = spaces_load('taxonomy', $tid);
$default_value = $space->controllers->variable
->get('spaces_preset_taxonomy', 'space');
if (isset($default_value, $form['spaces']['spaces_preset']['spaces_preset_taxonomy']['#options'][$default_value])) {
$form['spaces']['spaces_preset']['spaces_preset_taxonomy']['#default_value'] = $default_value;
}
}
}
}
}
function spaces_taxonomy_taxonomy($op, $type, $array = NULL) {
if ($type === 'term') {
$term = $array;
switch ($op) {
case 'insert':
case 'update':
$space = spaces_load('taxonomy', $term['tid']);
if ($space) {
if (!empty($term['spaces_preset_taxonomy'])) {
$space->controllers->variable
->set('spaces_preset_taxonomy', $term['spaces_preset_taxonomy']);
}
$modifier = array(
'provider' => 'spaces_taxonomy',
'id' => $term['tid'],
'value' => $term['purl']['value'],
);
purl_save($modifier);
}
break;
case 'delete':
spaces_delete('taxonomy', $term['tid']);
$modifier = array(
'provider' => 'spaces_taxonomy',
'id' => $term['tid'],
);
purl_delete($modifier);
break;
}
}
}
function spaces_taxonomy_settings(&$form_state) {
$form = array();
$vocabs = array(
0 => '---',
);
foreach (taxonomy_get_vocabularies() as $vocab) {
if (!$vocab->multiple && !$vocab->tags) {
$vocabs[$vocab->vid] = $vocab->name;
}
}
$form['spaces_taxonomy_vid'] = array(
'#type' => 'select',
'#title' => t('Spaces vocabulary'),
'#description' => t('Choose one of the following vocabularies to enable for use with Spaces.'),
'#options' => $vocabs,
'#default_value' => variable_get('spaces_taxonomy_vid', 0),
);
$form = system_settings_form($form);
return $form;
}