ฉันต้องการอัปเดตคำตอบถอดรหัสถอดรหัสแม่มดให้ฉันวิธีที่ดีที่สุดถ้าคุณไม่ต้องการเพิ่มโมดูลอื่นเพื่อให้เหมาะกับ Drupal 7:
/**
* Implements hook_permission().
*/
function MYMODULE_permission() {
$perms = array(
'administer status of any content' => array(
'title' => t('Administer status for all content type'),
'description' => t(''),
'restrict access' => true
),
);
foreach (node_type_get_types() as $type) {
if (isset($type->type)) {
$perm_types = array(
'administer status of any '. check_plain($type->type) .' content' => array(
'title' => t('Administer status of any '. check_plain($type->type) .' content'),
'description' => t(''),
),
'administer status of own '. check_plain($type->type) .' content' => array(
'title' => t('Administer status of own '. check_plain($type->type) .' content'),
'description' => t(''),
),
);
$perms = array_merge($perms,$perm_types);
}
}
return $perms;
}
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if (preg_match('/_node_form$/', $form_id) && _MYMODULE_access($form['#node']->type)) {
if ($form['options']['#access'] == FALSE) {
$form['options']['#access'] = TRUE;
}
}
}
function _MYMODULE_access($type) {
return user_access('administer status of any content')
|| user_access('administer status of any ' . check_plain($type) . ' content')
|| user_access('administer status of own ' . check_plain($type) . ' content');
}