You are here

如何在action模块中添加新动作

mabin830707 的头像
Submitted by mabin830707 on 星期四, 2012-12-27 13:49

在开发网站时,安装了private message模块,用于站内发送短消息,现在想在action模块中添加个用于自动调用private message的动作,用于配合trigger在某种特定情况下可以自动发送短消息,请问应该如何实现?谢谢

论坛:

Drupal版本:

g089h515r806 的头像

trigger模块已经被淘汰了,Drupal8中,已经被移除了Drupal内核,现在此类问题的解决办法,都是使用Rules模块。

我最近编写的breadcrumb2(面包屑)模块,基于实体实现面包屑,同时集成了Rules,里面有rules自定义动作的示例,你可以下载该模块作为rules自定义动作的参考。

这里粘贴一点breadcrumb2(面包屑)模块rules集成的部分代码,供你参考:

 

/**
 * Implements hook_rules_action_info().
 */
function breadcrumb2_rules_action_info() {
  $items = array();

  $items['breadcrumb2_append_breadcrumb_trail'] = array(
    'label' => t('Append breadcrumb trail'),
    'group' => t('Breadcrumb2'),
    'parameter' => array(
      'breadcrumb' => array(
        'type' => 'breadcrumb2',
        'label' => t('Breadcrumb'),
        'description' => t('The breadcrumb object who will be appended.'),
        'wrapped' => TRUE,
        'save' => FALSE,
      ),
      'title' => array(
        'type' => 'text',
        'label' => t('title'),
        'wrapped' => FALSE,
      ),
      'url' => array(
        'type' => 'text',
        'label' => t('URL'),
        'wrapped' => FALSE,
      ),
    ),
    'base' => 'breadcrumb2_rules_append_breadcrumb_trail',
    'access callback' => 'breadcrumb2_rules_integration_access',
  );

  $items['breadcrumb2_fetch_lightest_term_from_node'] = array(
    'label' => t('Fetch lightest term from node'),
    'group' => t('Breadcrumb2'),
    'parameter' => array(
      'node' => array(
        'type' => 'node',
        'label' => t('Node'),
        'wrapped' => TRUE,
        'save' => FALSE,
      ),
    ),
    'base' => 'breadcrumb2_rules_fetch_lightest_term_from_node',
    'access callback' => 'breadcrumb2_rules_integration_access',
    'provides' => array(
      'lightest_term' => array(
        'type' => 'taxonomy_term',
        'label' => t('First term'),
      ),
    ),
  );
 
  $items['breadcrumb2_taxonomy_get_parents_all'] = array(
    'label' => t('Taxonomy get parents all'),
    'group' => t('Breadcrumb2'),
    'parameter' => array(
      'taxonomy_term' => array(
        'type' => 'taxonomy_term',
        'label' => t('Taxonomy term'),
        'wrapped' => TRUE,
        'save' => FALSE,
      ),
    ),
    'base' => 'breadcrumb2_rules_taxonomy_get_parents_all',
    'access callback' => 'breadcrumb2_rules_integration_access',
    'provides' => array(
      'parent_terms' => array(
        'type' => 'list<taxonomy_term>',
        'label' => t('Parent terms'),
      ),
    ),
  );   
  return $items;
}