我不知道如何从JavaScript代码触发drupal规则。

      lowerLayer[image.feature_nid].on("dragend", function() {
               var position = kineticImage.getPosition();
               var layerPosition = this.getPosition();
               var slotNid = kineticImage.slot_nid;
               positionX = position.x + layerPosition.x;
               positionY = position.y + layerPosition.y;
               //Here I want to call drupal rule
        });


我评论了我需要触发drupal规则的那一行。我可以使用这些参数(slotNid,positionX,positionY)调用drupal规则,就像我可以调用某些函数(someFunction(slotNid,positionX,positionY)一样。

欢迎任何解决方案。

最佳答案

Clive所述,您可以通过ajax调用来实现。
您需要在自定义模块的menu hook下设置页面回调,并且您可以在其中提及调用页面请求的功能。

Example:
// this code will go under menu hook
$items['ajax/rule1.1'] = array(
    'title' => 'Rule 1.1',
    'page callback' => 'custom_rule_trigger',
    'access arguments' => array('access content'),
    'file' => 'custom_rules.inc',
  );

// then you can write php code which you want to execute under custom_rule_trigger function in custom_rules.inc file.
function custom_rule_trigger(){
// write your rules here..
}


在javascript中,您可以调用www.example.com/ajax/rule1.1网址来触发规则。

希望这会有所帮助。

关于javascript - 如何从JavaScript代码触发Drupal规则,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16835666/

10-17 02:50