如果你願意,你可以研究OnlyOne模塊的代碼(沙箱)看到一個簡單的方法來實現這一點。
只有一個模塊允許在該配置的選定內容類型中爲每種語言 創建只有一個節點。
/**
* Implements hook_form_alter().
* @param $form
* @param $form_state
* @param $form_id
*/
function onlyone_form_alter(&$form, &$form_state, $form_id) {
$onlyone_content_types = variable_get('onlyone_node_types');
//getting the name of the node type
$node_type = substr($form_id, 0, -10);
//Verifying if the new node should by onlyone
if (isset($onlyone_content_types) && in_array($node_type, $onlyone_content_types, TRUE)) {
$node = $form_state['node'];
//if we are trying to create a new node
if (!isset($node->nid) || isset($node->is_new)) {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', $node_type);
if (drupal_multilingual()) {
global $language;
$query->propertyCondition('language', $language->language);
}
$result = $query->execute();
//if we have one node, then redirect to the edit page
if (isset($result['node'])) {
$nid = array_keys($result['node'])[0];
drupal_goto('node/' . $nid . '/edit');
}
}
}
}
披露:我是模塊OnlyOne的維護者。
我梅南方法1)可能會更好,如果你有千兆網站需要核心優化 – henrijs 2010-05-03 10:39:12
哇,我以爲我已經仔細研究了contrib模塊...不要猜測。感謝您的鏈接。我會接受答案,如果一個人爲我工作 – Chaulky 2010-05-03 13:45:23
結束了一個開發人員已經得到了角色切換方法的工作,所以我們不會混亂它。但我很欣賞這些鏈接,未來可能會找到其中一個模塊 – Chaulky 2010-05-04 15:31:31