Entity Translation module relies on the $form['#entity_type'] being correct to function properly - in my case set to 'commerce_product'.

Currently, when using Auto Product Display this is being overwritten to be 'node' by this line:

// Attach the product display form to product creation variable.
    field_attach_form('node', $node, $form, $form_state);

Comments

bogeyman’s picture

Status: Active » Postponed (maintainer needs more info)

Would you like to describe more about the error? Like what kind error message or wrong result that you got.

grahamc’s picture

Trying to add a new translation gives me a screenful of these:

Notice: Undefined index: entity keys in entity_extract_ids() (line 7627 of /home/graham/projects/sites/sitename/htdocs/includes/common.inc). Backtrace:
entity_extract_ids(NULL, NULL) field.attach.inc:191
_field_invoke('form', NULL, NULL, Array, Array, Array) field.attach.inc:386
_field_invoke_default('form', NULL, NULL, Array, Array, Array) field.attach.inc:568
field_attach_form(NULL, NULL, Array, Array, 'ar') entity_translation.module:1211
entity_translation_prepare_element(Array, Array, Array) form.inc:1801
form_builder('commerce_product_ui_product_form', Array, Array) form.inc:1857
form_builder('commerce_product_ui_product_form', Array, Array) form.inc:842
drupal_process_form('commerce_product_ui_product_form', Array, Array) form.inc:374
drupal_build_form('commerce_product_ui_product_form', Array) form.inc:131
drupal_get_form('commerce_product_ui_product_form', Object) commerce_product_ui.products.inc:66
commerce_product_ui_product_form_wrapper(Object) 
call_user_func_array('commerce_product_ui_product_form_wrapper', Array) entity_translation.module:668
_entity_translation_callback('commerce_product_ui_product_form_wrapper', Array, Array) entity_translation.module:657
entity_translation_add_page('commerce_product', Object, 'ar', 'en-gb', Array, Object) 
call_user_func_array('entity_translation_add_page', Array) menu.inc:517
menu_execute_active_handler() index.php:21

The badness starts in entity_translation_prepare_element(), which calls this function:

function entity_translation_edit_form_info($form, $form_state) {
  $info = FALSE;

  if (isset($form['#entity_type'])) {
    $entity_info = entity_get_info($form['#entity_type']);
    if (!empty($entity_info['translation']['entity_translation']['edit form'])) {
      $entity_key = $entity_info['translation']['entity_translation']['edit form'];
      if (isset($form_state[$entity_key])) {
        $info = array(
          'entity type' => $form['#entity_type'],
          'entity' => (object) $form_state[$entity_key],
        );
      }
    }
  }

  return $info;
}

... which returns FALSE when Commerce APD is being used.

This causes the source translations to not display in the edit form, and saving the translated entity makes it forget that there ever was another original translation. So, broken ;-)

It looks like the product display node probably ought to be added to the $form array somewhere below the top level - field_attach_form() definitely allows it to be a sub-element. In my case though, just re-setting the '#entity_type' key is enough to make things work again.

webcurl’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new4.15 KB

Putting the product display form in a subkey of the product form (patch attached) does indeed seem to correct this issue, along with two others:

Field display order on the Product edit form is different to the 'Manage fields' page
(metatag module) Product metatags not displayed in edit form, again because of incorrect $form['#entity_type']

lisa.rae’s picture

This issue not only breaks the EntityTranslation functionality, but any functionality that relies on EntityFieldQuery working properly when using product_id on the #entity.

I had a custom module that was using EntityFieldQuery to add some lookup funtionality to the commerce product ui form, and that funtionality broke to the extent that even uninstalling the commerce_apd module did not fix it -- I had to revert back to a previous database.

Applying this patch worked in my case; however the codebase has been updated since this patch was originally created, and I had to apply it manually to version 1.4, after which the broken EntityFieldQuery calls in my custom module started working again.

This patch probably needs to be updated, and incorporated into the next release.

  • bogeyman committed 6837fd7 on 7.x-1.x
    Issue #1993614 by webcurl: Breaks Entity Translation functionality
    
bogeyman’s picture

Sorry for the very very late reply. I have updated the patch and committed it to 7.x-1.x. Please review it.

bogeyman’s picture

Status: Needs review » Fixed
bogeyman’s picture

Status: Fixed » Closed (fixed)