Hier ist ein vollständiges Modul zum Ausführen der Aufgabe sowie das Zuweisen einer Rolle, um dieses Verhalten damit auszuführen:
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);
}
Erstellen Sie die beiden oben genannten Dateien in einem Ordner, benennen Sie ihn saidbakr_tools
und laden Sie ihn dann in Ihre Drupal-Installation unter hoch sites/all/modules
.
In dieser Lösung zum Testen des Veröffentlichungsstatus von Knoten habe ich verwendet $node->status