Hi,

1)What is an instance? and what is the difference between an instance and a field ?

like that:
$field = field_info_field('body');
$instance = field_info_instance('node', 'body', $type->type);

2) what is the mean of the bold functions in that code:
_job_post_installed_fields()
_job_post_installed_instances()

function job_post_install() { //job posting install module
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['job_post']);
$body_instance = field_info_instance('node', 'body', 'job_post');
$body_instance['type'] = 'text_summary_or_trimmed';
field_update_instance($body_instance);

foreach (_job_post_installed_fields() as $field) {
field_create_field($field);
}

foreach (_job_post_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = 'job_post';
field_create_instance($instance);
}

}

and what is the instance variable ? ($instance)

Comments

Difference

A field instance is exactly that... an instance of a specific field definition. Once a field is defined, that field can then have an instance in multiple entity types. The body field is a good example of this. That one field has an instance in multiple entity types. A field can be defined without instances, but it must have an instance in order to actually be used for storing data.

The $instance variable is being used in the foreach loop to iterate through all elements of the array created by the function _job_post_installed_instances(). The first foreach loop is creating field definitions. The second foreach loop is creating instances of fields in the job_post node type.

Heinz D. Wegener
http://element31.com

nobody click here