Active
Project:
Restricted content
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
13 Jan 2010 at 23:19 UTC
Updated:
13 Jan 2010 at 23:19 UTC
I thought it would be great for this module to integrate with the rules module so that, for instance, permission could be applied at the time of saving content for certain paths in the site. For example, if a node is saved with the path /members then it would automatically be assigned with the member only permission.
I've had a go at this, and come up with a very basic implementation of this, and I'm posting it here if anyone wants to run with it.
restricted_content.rules.inc
// Rules definitions
/**
* Implementation of hook_rules_action_info().
*/
function restricted_content_rules_action_info() {
$info = array();
$info['restricted_content_rules_action_populate_field'] = array(
'label' => t('Set restricted content to members only'),
'arguments' => array(
'node' => array(
'type' => 'node',
'label' => t('Content'),
),
),
'help' => t('Set restricted content to members only.'),
'module' => 'System',
);
return $info;
}
function restricted_content_rules_action_populate_field($node) {
$rids = unserialize(db_result(db_query("SELECT rids FROM {restricted_content} WHERE nid = %d", $node->nid)));
$key = array_search('Member', user_roles() );
if (empty($rids) ) {
$rids = array();
}
if (!array_search($key,$rids)) {
array_push($rids,$key);
db_query("DELETE FROM {restricted_content} WHERE nid = %d", $node->nid);
db_query("INSERT INTO {restricted_content} VALUES (%d, '%s')", $node->nid, serialize($rids));
}
}