简体   繁体   English

Drupal 6不支持的操作数类型?

[英]Drupal 6 Unsupported operand type?

I'm running Drupal 6 on my local machine with PHP 5.5 and I am getting an unsupported operand type when I try to add a node of a content type being made via a module. 我在使用PHP 5.5的本地计算机上运行Drupal 6,并且在尝试添加通过模块生成的内容类型的节点时,遇到了不受支持的操作数类型。

The error is being triggered in function drupal_render which can be found in commons.inc . 该错误在function drupal_render中触发,可以在commons.inc找到该commons.inc the line is $elements += array('#title' => NULL, '#description' => NULL); 该行是$elements += array('#title' => NULL, '#description' => NULL); . I have done a var_dump and discovered for some reason my element is a boolean of true instead of an array. 我做了一个var_dump ,由于某种原因发现我的元素是布尔值true而不是数组。 I can't figure out why. 我不知道为什么。

Here's my module file that creates the form 这是我创建表单的模块文件

<?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;
}
?>

The error you are seeing is because of an incorrectly keyed $form element. 您看到的错误是由于错误地键入了$ form元素。 All form elements need to have a '#' character before the key name. 所有表单元素的键名称前都必须带有“#”字符。 (Why Drupal isn't smart enough to just ignore elements without '#' is beyond me.) (为什么Drupal不够聪明,无法忽略没有'#'的元素,这超出了我。)

The line that was causing an error is 'required' => true . 导致错误的行是'required' => true It needs to be '#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
    );
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM