services_ccc.module in Services Client 7
File
services_ccc/services_ccc.module
View source
<?php
function services_ccc_menu() {
$items['admin/structure/services_client/conditional_taxonomy'] = array(
'title' => 'Custom Condition',
'description' => 'Send node to remote site based on taxonomy',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'services_ccc_settings',
),
'access arguments' => array(
'administer services client',
),
'weight' => 20,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function services_ccc_settings() {
$form['services_ccc_connection_taxonomy'] = array(
'#type' => 'textfield',
'#title' => 'Field containing taxonomy terms',
'#default_value' => variable_get('services_ccc_connection_taxonomy', NULL),
);
return system_settings_form($form);
}
function services_ccc_node_insert($node) {
services_ccc_node_send($node);
}
function services_ccc_node_update($node) {
services_ccc_node_send($node);
}
function services_ccc_node_send($node) {
$vocab_field = variable_get('services_ccc_connection_taxonomy', NULL);
$conns_to_send = array();
if (!$vocab_field) {
return;
}
if (isset($node->{$vocab_field})) {
$lang = field_language('node', $node, $vocab_field);
foreach ($node->{$vocab_field}[$lang] as $num => $term) {
$conns_to_send[] = taxonomy_term_load($term['tid'])->name;
}
}
if (!empty($conns_to_send)) {
services_client_data_process($node, 'node_save', NULL, $conns_to_send, TRUE);
}
}