-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_to_drupal.module
67 lines (59 loc) · 1.67 KB
/
node_to_drupal.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Implements hook_menu().
*
* Opening up a page that only displays the form.
*
*/
function node_to_drupal_menu() {
$items['message-watchdog'] = array(
'title' => 'Log an event to watchdog',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_to_drupal_form'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* node_to_drupal_form()
*
* A VERY simple form for our menu callback.
*
*/
function node_to_drupal_form($form , &$form_state) {
drupal_add_js(drupal_get_path('module', 'node_to_drupal') . '/node_to_drupal.client.js');
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create a log entry!'),
);
return $form;
}
/**
* Implements hook_nodejs_message_callback().
*
* Look for the 'nodeToDrupal' as our 'messageType' coming from the node server.
* If we've found it, then define a custom handler and pass it back.
*
*/
function node_to_drupal_nodejs_message_callback($type) {
switch($type) {
case 'nodeToDrupal':
return array('node_to_drupal_handler');
}
return false;
}
/**
* node_to_drupal_handler()
*
* A callback handler that was specified in hook_nodejs_message_callback().
* If this handler fires it means we have recieved a message of the correct type.
* Perform the log to watchdog, and shoot back a responce to node.
*
*/
function node_to_drupal_handler($message, &$responce) {
// Grab our messageBody from the client message and post it to the watchdog.
watchdog('node_to_drupal', $message['messageBody'], array(), WATCHDOG_INFO);
// Tell node we got the message.
$responce = 'Message logged to Watchdog!';
}