2013-10-17 23 views
0

我在本地機器上用PHP 5.5運行Drupal 6,當我試圖添加一個通過模塊創建的內容類型的節點時,我得到了不受支持的操作數類型。Drupal 6不支持的操作數類型?

錯誤正在觸發function drupal_render可以在commons.inc找到。該行是$elements += array('#title' => NULL, '#description' => NULL);。我做了一個var_dump,並由於某種原因發現我的元素是一個真正的布爾值而不是數組。我無法弄清楚爲什麼。

下面是創建窗體

<?php 
// $ID$ 

function jokes_node_info(){ 
    return array(
     'jokes' => array(
      'name' => t('jokes'), 
      'module' => 'jokes', 
      'description' => t('Tell use your joke'), 
      'has_title' => true, 
      'title_label' => t('Title'), 
      'has_body', true, 
      'body_label' => t('jokes'), 
      'min_word_count' => 2, 
      'locked' => true 
     ) 
    ); 
} 


//only admin can create jokes 
function jokes_menu_alter(&$callback){ 
    if(!user_access('administer nodes')){ 
     $callback['node/add/jokes']['access callback'] = false; 
     unset($callback['node/add/jokes']['access arguments']); 
    } 
} 

//create permissions 
function jokes_perm(){ 
    return array(
     'create jokes', 
     'edit own jokes', 
     'edit any jokes', 
     'delete own jokes', 
     'delete any jokes' 
    ); 
} 

//control access 
function jokes_access($op, $node, $account){ 
    $is_author = $account->uid == $node->uid; 
    switch ($op) { 
     case 'create': 
      return user_access('create jokes', $account); 
     case 'edit': 
      return user_access('edit own jokes', $account) && $is_author || user_access('edit any jokes', $account); 
     case 'delete': 
      return user_access('delete own jokes', $account) && $is_author || user_access('delete any jokes', $account); 
     default: 
      break; 
    } 
} 

function jokes_form($node){ 
    $type = node_get_types('type', $node); 

    $form['title'] = array(
     '#type' => 'textfield', 
     '#title' => check_plain($type->title_label), 
     '#required' => true, 
     '#default_value' => $node->title, 
     '#weight' => -5, 
     '#maxlength' => 255 
    ); 
    $form['body_filter']['body'] = array(
     '#type' => 'textarea', 
     '#title' => check_plain($type->body_label), 
     '#default_value' => $node->body, 
     '#rows' => 7, 
     'required' => true 
    ); 
    $form['body_filter']['filter'] = filter_form($node->format); 
    $form['punchline'] = array(
     '#type' => 'textfield', 
     '#title' => t('Punchline'), 
     '#required' => true, 
     '#default_value' => isset($node->punchline) ? $node->punchline : '', 
     '#weight' => 5 
    ); 
    return $form; 
} 
?> 

回答

1

您所看到的錯誤是由於不正確的密鑰$表單元素我的模塊文件。所有表單元素都需要在密鑰名稱前加'#'字符。 (爲什麼Drupal不夠聰明,只是忽略沒有'#'的元素超出了我的範圍。)

導致錯誤的行是'required' => true。它需要是'#required' => true

<?php 
    $form['body_filter']['body'] = array(
     '#type' => 'textarea', 
     '#title' => check_plain($type->body_label), 
     '#default_value' => $node->body, 
     '#rows' => 7, 
     '#required' => true 
    ); 
?> 
相關問題