Skip to content

Instantly share code, notes, and snippets.

@sebyoga
Created June 18, 2013 15:22
Show Gist options
  • Save sebyoga/5806287 to your computer and use it in GitHub Desktop.
Save sebyoga/5806287 to your computer and use it in GitHub Desktop.
function MYMODULE_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',
),
);
field_create_instance($instance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment