<?php
/**
* Implementation of hook_enable().
*/
function addexample_enable() {
// Check if our field is not already created.
if (!field_info_field('field_myfield')) {//--字段名称需要小写
$field = array(
'field_name' => 'field_myfield',
'type' => 'text',
);
field_create_field($field);
// Create the instance on the bundle.
$instance = array(
'field_name' => 'field_myfield',
'entity_type' => 'user',
'label' => 'My Field Name',
'bundle' => 'user',
// If you don't set the "required" property then the field wont be required by default.
'required' => TRUE,
'settings' => array(
// Here you inform either or not you want this field showing up on the registration form.
'user_register_form' => 1,
),
'widget' => array(
'type' => 'textfield',
'weight' => '1',
),
);
field_create_instance($instance);
}
}
?>
http://drupal.stackexchange.com/questions/8253/how-to-add-extra-fields-to-user-profile
板块
Drupal 版本
(无主题)