Is there a way to create a Field Collection with Fields when you install a module, using field_create_field and field_create_instance? I tried dumping out the instances with this snippet:

$entity_type = 'myentity';
	$field_name = 'field_table_rates';
	$bundle_name = 'myentity';

	$info_config = field_info_field($field_name);
	$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
	unset($info_config['id']);
	unset($info_instance['id'], $info_instance['field_id']);
	include_once DRUPAL_ROOT . '/includes/utility.inc';
	$output1 = "field_create_field(" . drupal_var_export($info_config) . ");\n";
	$output2 = "field_create_instance(" . drupal_var_export($info_instance) . ");";
	krumo($output1);krumo($output2);exit;

It seems to create the Field Collection and its fields fine, but does not create an instance. Also, the field itself is not able to be selected and attached via the Manage Field screen, its not listed in the group of available fields.

Comments

jmuzz’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

I'm not sure what myentity and field_table_rates are. My guess is that field_table_rates is the name of a field collection bundle that was made before this part of the code. If that is the case, the field for it will not exist yet, field_info_field will not return something you can use and you will need to supply your own values to field_create_field.

If that doesn't help, can you explain what myentity and field_table_rates are?

jmuzz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)