workbench_moderation_state_access.module in Workbench Moderation State Access 7
File
workbench_moderation_state_access.module
View source
<?php
function workbench_moderation_state_access_permission() {
$permissions = array();
$states = workbench_moderation_states();
foreach ($states as $state) {
$permissions["edit all content in {$state->name}"] = array(
'title' => t('Edit all content in @state', array(
'@state' => $state->label,
)),
);
if (variable_get('workbench_moderation_per_node_type', FALSE)) {
$node_types = workbench_moderation_moderate_node_types();
foreach ($node_types as $node_type) {
$permissions["edit {$node_type} in {$state->name}"] = array(
'title' => t('Edit @node_type in @state', array(
'@node_type' => node_type_get_name($node_type),
'@state' => $state->label,
)),
);
}
}
}
return $permissions;
}
function workbench_moderation_state_access_node_access($node, $op, $account) {
if ($op == 'update' && isset($node->workbench_moderation)) {
$state = $node->workbench_moderation['current']->state;
$type = variable_get('workbench_moderation_per_node_type', FALSE);
$permission = $type ? "edit {$node->type} in {$state}" : "edit all content in {$state}";
if (!user_access($permission, $account)) {
return NODE_ACCESS_DENY;
}
}
return NODE_ACCESS_IGNORE;
}