diff --git a/inline_entity_form.module b/inline_entity_form.module index ecfe927..095a083 100644 --- a/inline_entity_form.module +++ b/inline_entity_form.module @@ -224,6 +224,9 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins // Add entity type specific CSS. _inline_entity_form_attach_css($controller->css(), $element['#attached']['css']); + // Add a validator for setting the inline entities language. + $form['#validate'][] = 'inline_entity_form_update_language_validate'; + // Initialize the IEF array in form state. if (empty($form_state['inline_entity_form'][$ief_id])) { $form_state['inline_entity_form'][$ief_id] = array( @@ -471,6 +474,32 @@ function inline_entity_form_field_widget_form(&$form, &$form_state, $field, $ins } /** + * Validation callback for forms holding an inline entity form. + * + * Sets the inline entities language to the language selected on the form. + */ +function inline_entity_form_update_language_validate(&$form, &$form_state) { + // Ignore the procedure if there was no language selection or if the neutral + // language was selected. + if (empty($form_state['values']['language']) || $form_state['values']['language'] == LANGUAGE_NONE) { + return; + } + + // Iterate the inline entities and set their language. + foreach ($form_state['inline_entity_form'] as &$ief) { + foreach ($ief['entities'] as &$entity) { + // Ignore entities which already have some language defined. + if (!empty($entity['entity']->language) && $entity['entity']->language != LANGUAGE_NONE) { + continue; + } + + $entity['entity']->language = $form_state['values']['language']; + $entity['needs_save'] = TRUE; + } + } +} + +/** * Wraps and returns the entity form provided by the passed-in controller. * * @param $controller