回答:
はい、カスタムモジュールで動的ルールを定義できます。見るhook_node_access
次に実装例を示します。
/**
* Implements hook_node_access().
*/
function MYMODULE_node_access($node, $op, $account) {
if (
// The $node argument can be either a $node object or a machine name of
// node's content type. It is called multiple times during a page load
// so it is enough if you perform the check once you get the object.
is_object($node) && $node->type == 'story' &&
// Operation on which you want to act: "create", "delete", "update", "view".
$op == 'update'
) {
// Check if the node is published.
if ($node->field_published[LANGUAGE_NONE][0]['value'] == 1) {
return NODE_ACCESS_DENY;
}
}
}
以下は、タスクを実行するための完全なモジュールと、その動作を実行するための役割の割り当てです。
saidbakr_tools.info
:
name = SaidBakr Tools
description = Tools offered by Said Bakr said.fox@gmail.com
core = 7.x
configure = admin/config/administration/saidbakr_tools
saidbakr_tools.module
:
<?php
/**
* Implements hook_node_access().
*/
function saidbakr_tools_node_access($node, $op, $account) {
global $user;
if (
// The $node argument can be either a $node object or a machine name of
// node's content type. It is called multiple times during a page load
// so it is enough if you perform the check once you get the object.
is_object($node) && $node->type == 'article' &&
// Operation on which you want to act: "create", "delete", "update", "view".
$op == 'update'
) {
// Check if the node is published.
// var_dump($node);
if ($node->status == 1 && in_array(variable_get('saidbakr_tools_role','author'), $user->roles)) {
return NODE_ACCESS_DENY;
}
}
}
/**
* Implements hook_menu().
*/
function saidbakr_tools_menu() {
$items = array();
$items['admin/config/administration/saidbakr_tools'] = array(
'title' => 'SaidBakr Tools',
'description' => 'Settings for SaidBakr Tools!',
'page callback' => 'drupal_get_form',
'page arguments' => array('saidbakr_tools_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Page callback: Current posts settings
*
* @see saidbakr_tools_menu()
*/
function saidbakr_tools_form($form, &$form_state) {
$form['saidbakr_tools_role'] = array(
'#type' => 'textfield',
'#title' => t('The role name'),
'#default_value' => variable_get('saidbakr_tools_role', 'author'),
'#size' => 20,
'#maxlength' => 24,
'#description' => t('Enter the role name that its users should not be able to edit published contents.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
上記の2つのファイルをフォルダーに作成し、名前を付けてsaidbakr_tools
、Drupalのにアップロードしますsites/all/modules
。
ノードの発行ステータスをテストするこのソリューションでは、私は $node->status