如何“打包” Drupal 7 中的高级操作和设置触发器
我在代码中创建了两种操作,一种简单,一种高级。
function userbeep_action_info() {
return array(
'userbeep_beep_action' => array(
'type' => 'system',
'label' => t('Beep annoyingly'),
'configurable' => FALSE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
),
'userbeep_multiple_beep_action' => array(
'type' => 'system',
'label' => t('Beep multiple times'),
'configurable' => TRUE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
)
);
}
现在,简单操作(即不可配置的操作)将自动出现在我的“触发器”菜单中,但我需要在 admin/config/system/actions
中创建高级操作,然后才能使用它。
我想做的是让我的模块自动创建高级操作。我可以通过两种方式看到它的工作原理:
1)向 .install 文件添加一些内容,以便在加载模块时安装和卸载。
2) 使用功能打包这些设置
理想情况下,我想使用 1) 以编程方式执行此操作,但我也热衷于了解功能。我安装了该模块,但没有看到明显的方法来做到这一点。
展望未来,是否还有一种方法可以使用这些操作来打包/设置触发器,以便用户不必手动设置?
I have created two actions in code, one simple and one advanced.
function userbeep_action_info() {
return array(
'userbeep_beep_action' => array(
'type' => 'system',
'label' => t('Beep annoyingly'),
'configurable' => FALSE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
),
'userbeep_multiple_beep_action' => array(
'type' => 'system',
'label' => t('Beep multiple times'),
'configurable' => TRUE,
'triggers' => array('node_view', 'node_insert', 'node_update', 'node_delete')
)
);
}
Now the simple action (i.e. the non-configurable one) will appear in my Triggers menu automatically, but I need to create the advanced one in admin/config/system/actions
before I can use it.
What I'd like to do is have my module automatically create the advanced action. There are two ways I can see this working:
1) Add something to an .install file to install and uninstall upon loading the module.
2) Package these settings using Features
Ideally, I'd like to do this programmatically using 1), but I'm also keen to learn about Features. I installed the module but saw no obvious way to do this.
Moving forwards, would there also be a way to package / set up the Trigger using these actions so that the user doesn't have to set this up manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 您可以使用 Actions API 方法 -
actions_save
和actions_delete
来实现此目的。 (参见includes/actions.inc)。hook_install(),
hook_uninstall(),
2) 功能是否支持导出操作?我认为,对于打包不可配置的操作,
hook_action_info()
已经足够好了。3) 同样,使用代码,您可以通过向
trigger_assignments
表添加条目来显式为触发器分配操作,如下所示:1) You can use the Actions API methods -
actions_save
andactions_delete
for this. (See includes/actions.inc).hook_install(),
hook_uninstall(),
2) Does Features support exporting actions? For packaging non-configurable actions,
hook_action_info()
is good enough, I feel.3) Again, using code, you can explicitly assign actions to triggers by adding entries to the
trigger_assignments
table as shown below: