【发布时间】:2016-07-07 08:43:00
【问题描述】:
以下是我到目前为止所做的以及我正在尝试做的信息。
到目前为止我做了什么
- Nodejs 模块和 drupal 8 完成。示例模块运行良好。
- 在 drupal 8 中创建了一个简单的模块,包含一个名为 simple
形式。在它的提交函数上,调用 nodejs 模块函数将我的消息排入频道。 - 在 nodejs 入队消息中定义的 JavaScript 回调函数。
我一直在努力实现的目标
- 提交文本表单时。只是为了更新drupal 8中的块。(用hello world更新块内容。)
问题
- 我与 nodejs 关联的 javascript 回调没有被调用。
以下是我的代码。
提交功能码
public function submitForm(array &$form, FormStateInterface $form_state) {
/*$message->broadcast = TRUE;
* This would normally be replaced by code that actually does something
* with the title.
*/
$title = $form_state->getValue('title');
$message = (object) array(
'channel' => 'example',
'broadcast' => TRUE,
'callback' => 'example',
'data' => array(
'message' => 'Hello World'
),
);
nodejs_enqueue_message($message);
drupal_set_message(t('You specified a title of %title.', ['%title' => $title]));
}
Javascript 回调代码
(function ($) {
Drupal.Nodejs.callbacks.example = {
//grab the message and inject into the header
callback: function (message) {
console.log('simple example');
if(message.channel == 'example') {
$('#nodejs-selector').html(message.data.body);
}
}
};
})(jQuery);
对此有任何帮助,我将不胜感激。如果有人需要,我很乐意提供这方面的更多信息。
【问题讨论】:
标签: javascript php node.js drupal-modules drupal-8