Creating fields <= hook_install()
// Add a field for the body.
node_add_body_field($node_type, $t('Description'));
// Create fields.
$fields = array();
$fields['example_unit_count'] = array(
'field_name' => 'example_unit_count',
'type' => 'number_integer',
// Optional.
'cardinality' => 1,
'settings' => array(
'max_length' => 5,
),
);
$fields['example_latitude'] = array(
'field_name' => 'example_latitude',
'type' => 'number_float',
'settings' => array(
'max_length' => 20,
),
);
$fields['example_longitude'] = array(
'field_name' => 'example_longitude',
'type' => 'number_float',
'settings' => array(
'max_length' => 20,
),
);
$fields['example_turbine_manufacturer'] = array(
'field_name' => 'example_turbine_manufacturer',
'type' => 'text',
'settings' => array(
'max_length' => 60,
),
);
foreach ($fields as $field) {
field_create_field($field);
}
// Create Field Instances.
$instances = array();
$instances['example_unit_count'] = array(
'field_name' => 'example_unit_count',
'label' => $t('Number of Units'),
'description' => $t('Number of individual units at a given Facility'),
'widget' => array(
'type' => 'text_textfield',
),
'required' => TRUE,
'settings' => array(
'text_processing' => 0,
),
);
$instances['example_latitude'] = array(
'field_name' => 'example_latitude',
'label' => $t('Latitude'),
'description' => $t('Signed degrees format (DDD.dddd)'),
'widget' => array(
'type' => 'text_textfield',
),
'settings' => array(
'text_processing' => 0,
),
'display' => array(
'default' => array(
'type' => 'hidden',
),
),
);
$instances['example_longitude'] = array(
'field_name' => 'example_longitude',
'label' => $t('Longitude'),
'description' => $t('Signed degrees format (DDD.dddd)'),
'widget' => array(
'type' => 'text_textfield',
),
'settings' => array(
'text_processing' => 0,
),
'display' => array(
'default' => array(
'type' => 'hidden',
),
),
);
$instances['example_turbine_manufacturer'] = array(
'field_name' => 'example_turbine_manufacturer',
'label' => $t('Turbine Manufacturer'),
'description' => $t('The name of the turbine manufacturer'),
'widget' => array(
'type' => 'text_textfield',
),
'display' => array(
'default' => array(
'label' => 'inline',
),
),
);
foreach ($instances as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = 'example';
field_create_instance($instance);
}
}
