2
什麼塊可見性PHP代碼段將僅顯示一個塊,只有在loged-in用戶可以編輯的節點頁面上?用戶可能不擁有該節點。就我而言,我想向實際填充缺失字段的用戶顯示Content Complete塊。在節點上顯示用戶可以編輯的塊?
什麼塊可見性PHP代碼段將僅顯示一個塊,只有在loged-in用戶可以編輯的節點頁面上?用戶可能不擁有該節點。就我而言,我想向實際填充缺失字段的用戶顯示Content Complete塊。在節點上顯示用戶可以編輯的塊?
支票node_access(「更新」,$節點)(更多http://api.drupal.org/api/function/node_access/6)
//first check whether it is a node page
if(arg(0) == 'node' && is_numeric(arg(1))){
//load $node object
$node = node_load(arg(1))
//check for node update access
if (node_access("update", $node)){
return TRUE;
}
}
以下是barraponto的解決方案改寫爲像我這樣的菜鳥,並支持多個條件。
<?php
$match = FALSE;
// Show block only if user has edit privilges for the node page
// first check whether it is a node page
if(arg(0) == 'node' && is_numeric(arg(1))){
//load $node object
$node = node_load(arg(1));
//check for node update access
if (node_access("update", $node)){
$match = TRUE;
}
}
return $match;
?>
+1 - 一個直接的解決方案。我會用'return node_access(「update」,$ node)'替換if子句,儘管;) – 2010-05-20 18:38:36
你是對的,儘管我的代碼稍微更清晰。但如果用戶知道PHP,你的建議就是最好的。 – 2010-05-21 17:42:01
只是做到這一點。 順便說一句,刪除那些主題評論,如果需要,創建另一個問題。 – 2010-05-22 00:34:34