用field_create_instance为article添加一个字段时,提示出错
提示错误信息如下:
Notice: Array to string conversion in eval() (line 10 ofF:\wamp\www\zy_test4\sites\all\modules\devel\devel.module(1415) : eval()'d code).
FieldException: Attempt to create an instance of field field_test_first on forbidden entity type node. in field_create_instance() (line 487 ofF:\wamp\www\zy_test4\modules\field\field.crud.inc).
代码如下:
$thefield = field_info_field('field_test_first');
if(empty($thefield)){
$thefield = array(
'entity_types' => array('node'),
'field_name' => 'field_test_first',
'type' => 'text',
);
$thefield = field_create_field($thefield);
}
print_r('thefield' .$thefield);
$theinstance = field_info_instance('node' , 'field_test_first' , 'Article');
if(empty($theinstance)){
$theinstance = array(
'bundle' => 'article',
'entity_type' => 'node',
'default_value' => NULL,
'deleted' => '0',
'field_name' => 'field_test_first',
'label' => 'the test first',
'required' => 0,
'title' => 'first title',
);
$theinstance = field_create_instance($theinstance);
}
print_r('theinstance' .$theinstance);