Last active
October 25, 2017 20:42
-
-
Save laradevitt/f4a91f821bb58a30450f7993f15f2196 to your computer and use it in GitHub Desktop.
Drupal 7.x: Example module that provides an exported rule that will email users assigned to current domain when content is created. (Domain Access, Rules)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Email domain users | |
description = Example module that provides a rule that will email users assigned to current domain. | |
core = 7.x | |
dependencies[] = domain | |
dependencies[] = domain_views | |
dependencies[] = entity | |
dependencies[] = node | |
dependencies[] = rules | |
dependencies[] = system | |
dependencies[] = views | |
dependencies[] = views_bulk_operations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Code for the Email domain users module. | |
*/ | |
/** | |
* Implements hook_views_api(). | |
*/ | |
function email_domain_users_views_api($module = NULL, $api = NULL) { | |
return array("api" => "3.0"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* email_domain_users.rules_defaults.inc | |
*/ | |
/** | |
* Implements hook_default_rules_configuration(). | |
*/ | |
function email_domain_users_default_rules_configuration() { | |
$items = array(); | |
$items['email_domain_users_contributor_creates_content'] = entity_import('rules_config', '{ "email_domain_users_contributor_creates_content" : { | |
"LABEL" : "Contributor creates content", | |
"PLUGIN" : "reaction rule", | |
"OWNER" : "rules", | |
"REQUIRES" : [ "rules", "views_bulk_operations" ], | |
"ON" : { "node_insert--article" : { "bundle" : "article" } }, | |
"IF" : [ | |
{ "entity_is_of_bundle" : { | |
"entity" : [ "node" ], | |
"type" : "node", | |
"bundle" : { "value" : { "article" : "article" } } | |
} | |
} | |
], | |
"DO" : [ | |
{ "views_bulk_operations_action_load_id_list" : { | |
"USING" : { "view" : "domain_users|default" }, | |
"PROVIDE" : { "entity_id_list" : { "domain_users_id_list" : "A list of entity ids" } } | |
} | |
}, | |
{ "LOOP" : { | |
"USING" : { "list" : [ "domain-users-id-list" ] }, | |
"ITEM" : { "domain_user_id" : "Domain user ID" }, | |
"DO" : [ | |
{ "entity_fetch" : { | |
"USING" : { "type" : "user", "id" : [ "domain-user-id" ] }, | |
"PROVIDE" : { "entity_fetched" : { "domain_user_entity" : "Domain user entity" } } | |
} | |
}, | |
{ "mail" : { | |
"to" : "[domain-user-entity:mail]", | |
"subject" : "A contributor ([node:author]) has created new content! ", | |
"message" : "Dear [domain-user-entity:name],\u000D\u000A\u000D\u000AA contributor has created new content for this domain.\u000D\u000A\u000D\u000AThe author is: [node:author]\u000D\u000A\u000D\u000ATo view the content, click this link (requires log-in): [node:url] \u000D\u000A\u000D\u000A------\u000D\u000AYou are receiving this email because you are assigned as an editor of this domain. \u000D\u000A\u000D\u000AThis email is automatically generated. Please do not reply to it. \u000D\u000A\u000D\u000A", | |
"from" : "[site:name] \\u003C[site:mail]\\u003E", | |
"language" : [ "" ] | |
} | |
} | |
] | |
} | |
} | |
] | |
} | |
}'); | |
return $items; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* email_domain_users.views_default.inc | |
*/ | |
/** | |
* Implements hook_views_default_views(). | |
*/ | |
function email_domain_users_views_default_views() { | |
$export = array(); | |
$view = new view(); | |
$view->name = 'domain_users'; | |
$view->description = ''; | |
$view->tag = 'default'; | |
$view->base_table = 'users'; | |
$view->human_name = 'Domain users'; | |
$view->core = 7; | |
$view->api_version = '3.0'; | |
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ | |
/* Display: Master */ | |
$handler = $view->new_display('default', 'Master', 'default'); | |
$handler->display->display_options['use_more_always'] = FALSE; | |
$handler->display->display_options['access']['type'] = 'perm'; | |
$handler->display->display_options['access']['perm'] = 'access user profiles'; | |
$handler->display->display_options['cache']['type'] = 'none'; | |
$handler->display->display_options['query']['type'] = 'views_query'; | |
$handler->display->display_options['exposed_form']['type'] = 'basic'; | |
$handler->display->display_options['pager']['type'] = 'none'; | |
$handler->display->display_options['pager']['options']['offset'] = '0'; | |
$handler->display->display_options['style_plugin'] = 'default'; | |
$handler->display->display_options['row_plugin'] = 'fields'; | |
$handler->display->display_options['row_options']['inline'] = array( | |
'uid' => 'uid', | |
); | |
/* Field: Bulk operations: User */ | |
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations'; | |
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'users'; | |
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations'; | |
$handler->display->display_options['fields']['views_bulk_operations']['label'] = ''; | |
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE; | |
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '0'; | |
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1; | |
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1; | |
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0; | |
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10'; | |
/* Sort criterion: User: Created date */ | |
$handler->display->display_options['sorts']['created']['id'] = 'created'; | |
$handler->display->display_options['sorts']['created']['table'] = 'users'; | |
$handler->display->display_options['sorts']['created']['field'] = 'created'; | |
$handler->display->display_options['sorts']['created']['order'] = 'DESC'; | |
/* Filter criterion: User: Active */ | |
$handler->display->display_options['filters']['status']['id'] = 'status'; | |
$handler->display->display_options['filters']['status']['table'] = 'users'; | |
$handler->display->display_options['filters']['status']['field'] = 'status'; | |
$handler->display->display_options['filters']['status']['value'] = '1'; | |
$handler->display->display_options['filters']['status']['group'] = 1; | |
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; | |
/* Filter criterion: Domain Editor: Domain ID */ | |
$handler->display->display_options['filters']['domain_id']['id'] = 'domain_id'; | |
$handler->display->display_options['filters']['domain_id']['table'] = 'domain_editor'; | |
$handler->display->display_options['filters']['domain_id']['field'] = 'domain_id'; | |
$handler->display->display_options['filters']['domain_id']['value'] = array( | |
'***CURRENT_DOMAIN***' => '***CURRENT_DOMAIN***', | |
); | |
$translatables['domain_users'] = array( | |
t('Master'), | |
t('more'), | |
t('Apply'), | |
t('Reset'), | |
t('Sort by'), | |
t('Asc'), | |
t('Desc'), | |
t('- Choose an operation -'), | |
); | |
$export['domain_users'] = $view; | |
return $export; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment