首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向Drupal7有机组角色成员发送电子邮件?

如何向Drupal7有机组角色成员发送电子邮件?
EN

Stack Overflow用户
提问于 2013-05-25 04:12:22
回答 2查看 2.4K关注 0票数 0

在Drupal7中,我想设置一个规则,根据某个操作向具有组织组角色的所有用户发送电子邮件。我知道如何采取行动,我知道如何做循环,我知道如何发送电子邮件。

我无论如何也想不出如何获得具有组角色"X“的组成员列表。

PS -我已经检查了这个链接:http://www.sthlmconnection.se/en/blog/rules-based-notifications-organic-groups,它是针对D6的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-26 03:58:22

我已经为OG https://drupal.org/node/1859698#comment-8719475提交了一个类似问题的补丁,它应该允许你在规则中这样做,而不需要自定义模块或需要知道角色id。

一旦你应用了这个补丁,你就可以使用"Get group members from group audience“操作,现在可以通过"Membership State”和"Group Roles“进行过滤。然后添加一个循环来遍历列表,并使用“发送邮件”操作向每个成员发送电子邮件。

票数 1
EN

Stack Overflow用户

发布于 2013-05-25 21:35:52

啊哈!(稍后还会有很多问题),答案如下:

自定义模块(myutil.module) - .module文件为空,具有任何其他模块所需的相同稀疏信息的.info文件。

使用以下代码添加文件myutil.rules.inc

代码语言:javascript
复制
/**
 * @file
 * Rules code: actions, conditions and events.
 */

/**
 * Implements hook_rules_action_info().
 */

function myutil_rules_action_info() {

  $actions = array(
    'myutil_action_send_email_to_group_editors' => array(
      'label'         => t('Get group editors from group audience'),
      'group'         => t('My Utilities'),
      'configurable'  => TRUE,
      'parameter' => array(
        'group_content' => array(
          'type' => 'entity',
          'label' => t('Group content'),
          'description' => t('The group content determining the group audience.'),
        ),
      ),
      'provides' => array(
        'group_editors' => array('type' => 'list<user>', 'label' => t('List of group editors')),
      ),
      'base'  => 'myutil_rules_get_editors',
    ),
  );

  return $actions;

}


function myutil_rules_get_editors($group_content) {

  if (!isset($group_content->og_membership)) {
    // Not a group content.
    return;
  }

  $members = array();
  foreach ($group_content->og_membership->value() as $og_membership) {
    // Get the group members the group content belongs to.
    $current_members = db_select('og_membership', 'om');
    $current_members->join('og_users_roles', 'ogur', 'om.etid = ogur.uid');
    $current_members->fields('om', array('etid'));
    $current_members->condition('om.gid', $og_membership->gid);
    $current_members->condition('om.entity_type', 'user');
    // FOR THIS LINE, YOU'LL NEED TO KNOW THE ROLE ID FROM THE `og_role` TABLE
    $current_members->condition('ogur.rid', 14);

    $result = $current_members->execute();
    while ($res = $result->fetchAssoc()) {
      $members[] = $res['etid'];
    }
  }
  // Remove duplicate items.
  $members = array_keys(array_flip($members));
  return array('group_editors' => $members);

}

像启用任何其他模块一样启用该模块。清除缓存。回到规则中去享受吧。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16742925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档