I have a custom module which creates a new entity and entity_type bundle.
As part of the .install file I have module_enable function which uses:

entity_save($type, entity_create($type, $values));

To create a few of the new entities and

field_create_field($field);

To create a few fields.
One of the fields created is of type 'entityreference' for which I create a new instance as below:

// Create the instance on the bundle.
$instance = array(
  'field_name' => 'new_addon_field', 
  'entity_type' => 'custom_entity', 
  'label' => 'A new field', 
  'bundle' => 'custom_entity_type_bundle', 
  'widget' => array(
      'type' => 'inline_entity_form',
      
      \\HOW TO PASS INLINE_ENTITY_FORM THE SETTINGS FOR TARGET ENTITY AND ALLOWABLE BUNDLES??
  ), 
);
field_create_instance($instance);

This all seams to work fine so far. However, how do you pass the settings to the widget so that the inline_entity_form has the correct pre-configured target entity and allowable bundles.

Comments

bojanz’s picture

Status: Active » Fixed

It's a field-level setting, not an IEF level setting.

  $field = array(
      'cardinality' => 1,
      'translatable' => FALSE,
      'settings' => array(
        'handler' => 'base',
        'handler_settings' => array(
          'target_bundles' => array(
            'article' => 'article',
          ),
        ),
        'target_type' => 'node',
      ),
      'module' => 'entityreference',
      'type' => 'entityreference',
    );

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.