You are here

function inline_entity_form_create_entity in Inline Entity Form 7

Creates a new entity of the given type and bundle.

Parameters

$entity_type: Entity type.

$bundle: Bundle.

$language: (Optional) The language to set, if the entity has a language key.

2 calls to inline_entity_form_create_entity()
inline_entity_form_entity_form in ./inline_entity_form.module
Wraps and returns the entity form provided by the passed-in controller.
inline_entity_form_settings in ./inline_entity_form.module
Introspects field and instance settings, and determines the correct settings for the functioning of the widget.

File

./inline_entity_form.module, line 1612
Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (for example, order -> line items), where the child entities are never managed outside the…

Code

function inline_entity_form_create_entity($entity_type, $bundle, $language = NULL) {
  $entity_info = entity_get_info($entity_type);
  $bundle_key = $entity_info['entity keys']['bundle'];
  $default_values = array();

  // If the bundle key exists, it must always be set on an entity.
  if (!empty($bundle_key)) {
    $default_values[$bundle_key] = $bundle;
  }

  // Set the language if we have both a language key and a language value.
  if (isset($language) && !empty($entity_info['entity keys']['language'])) {
    $language_key = $entity_info['entity keys']['language'];
    $default_values[$language_key] = $language;
  }
  return entity_create($entity_type, $default_values);
}