在drupal7中动态的为某个内容类型添加字段

来源:互联网 发布:qt 网络编程 编辑:程序博客网 时间:2024/05/25 05:38
 $myField_name = "my_new_field_name";    if(!field_info_field($myField_name)) // check if the field already exists.    {        $field = array(            'field_name'    => $myField_name,            'type'          => 'image',        );        field_create_field($field);        $field_instance = array(            'field_name'    => $myField_name,            'entity_type'   => 'node',            'bundle'        => 'CONTENT_TYPE_NAME',            'label'         => t('Select an image'),            'description'   => t(''),            'widget'        => array(                'type'      => 'image_image',                'weight'    => 10,            ),            'formatter'     => array(                'label'     => t('label'),                'format'    => 'image'            ),            'settings'      => array(                'file_directory'        => 'photos', // save inside "public://photos"                'max_filesize'          => '4M',                'preview_image_style'   => 'thumbnail',                'title_field'           => TRUE,                'alt_field'             => FALSE,            )        );        field_create_instance($field_instance);        drupal_set_message("Field created successfully!");    }

原创粉丝点击