function inline_entity_form_settings in Inline Entity Form 7
Introspects field and instance settings, and determines the correct settings for the functioning of the widget.
Settings:
- entity_type - The entity_type being managed.
- bundles - Bundles of entities that the user is allowed to create.
- column - The name of the ref. field column that stores the entity id.
4 calls to inline_entity_form_settings()
- inline_entity_form_autocomplete in ./
inline_entity_form.module - Returns output for inline entity form autocompletes.
- inline_entity_form_entity_delete in ./
inline_entity_form.module - Implements hook_entity_delete().
- inline_entity_form_field_widget_form in ./
inline_entity_form.module - Implements hook_field_widget_form().
- inline_entity_form_get_controller in ./
inline_entity_form.module - Returns the Inline Entity Form controller for the passed-in reference field.
File
- ./
inline_entity_form.module, line 313 - 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_settings($field, $instance) {
$settings = array(
'entity_type' => NULL,
'bundles' => array(),
'create_bundles' => array(),
'column' => NULL,
);
if ($field['type'] == 'commerce_product_reference') {
$settings['entity_type'] = 'commerce_product';
$settings['column'] = 'product_id';
// The product reference field has its bundle setting, use it.
$types = array_filter($instance['settings']['referenceable_types']);
if (!empty($types)) {
$settings['bundles'] = array_values($types);
}
}
elseif ($field['type'] == 'entityreference') {
$settings['entity_type'] = $field['settings']['target_type'];
$settings['column'] = 'target_id';
if (!empty($field['settings']['handler_settings']['target_bundles'])) {
$bundles = array_filter($field['settings']['handler_settings']['target_bundles']);
if (!empty($bundles)) {
$settings['bundles'] = array_values($bundles);
}
}
}
elseif ($field['type'] == 'commerce_line_item_reference') {
$settings['entity_type'] = 'commerce_line_item';
$settings['column'] = 'line_item_id';
}
// Allow other modules to alter the settings.
drupal_alter('inline_entity_form_settings', $settings, $field, $instance);
// If no specific bundle has been selected, assume all are available.
if (empty($settings['bundles'])) {
$info = entity_get_info($settings['entity_type']);
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
$settings['bundles'][] = $bundle_name;
}
}
// Now create a filtered list of bundles that the user has access to.
foreach ($settings['bundles'] as $bundle) {
$new_entity = inline_entity_form_create_entity($settings['entity_type'], $bundle);
if (entity_access('create', $settings['entity_type'], $new_entity)) {
$settings['create_bundles'][] = $bundle;
}
}
return $settings;
}