I receive next error when trying to replicate bean entity with translation programmatically:

Missing bundle property on entity of type bean. in entity_extract_ids()

Here is my code:

$clone = replicate_clone_entity('bean', $bean);
unset($clone->entity_translation_handler_id);
// Apply language from parent and take account of the language change.
if (empty($clone->language) || $clone->language != $replica->language) {
  $clone->language = $replica->language;
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  foreach (field_info_instances($entity_type, $bundle) as $instance) {
    $field_name = $instance['field_name'];
    $field = field_info_field($field_name);
    if ($field['translatable'] && isset($entity->{$field_name}[$source_langcode])) {
      $entity->{$field_name}[$target_langcode] = $entity->{$field_name}[$source_langcode];
      unset($entity->{$field_name}[$source_langcode]);
    }
  }
}
entity_save('bean', $clone);
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

a.milkovsky created an issue. See original summary.

a.milkovsky’s picture

Status: Active » Needs review
FileSize
460 bytes

There should be an additional logic in EntityTranslationBeanHandler to check if entity is new.

a.milkovsky’s picture

Issue summary: View changes
sylus’s picture

Status: Needs review » Reviewed & tested by the community

Thank you so much for this, this actually fixes a problem with deploy + uuid of beans with Entity Translation. The problem being you can't deploy a bean that has both en + fr fields without deploying the bean in just english first. Else you get the error mentioned in this issue.

Once we know the entity is new I can deploy a en + fr created bean without having to save + deploy just the english first. I think the "new" value helps the Entity Translaiton Handler fill out the following appropriately:

  "translations": {
    "original": "en",
    "data": {
      "en": {
        "entity_type": "bean",
        "entity_id": "{{bid}}",
        "revision_id": "{{vid}}",
        "language": "en",
        "source": "",
        "uid": "1",
        "status": "1",
        "translate": "0",
        "created": "1448940985",
        "changed": "1448940985"
      },
      "fr": {
        "entity_type": "bean",
        "entity_id": "{{bid}}",
        "revision_id": "{{vid}}",
        "language": "fr",
        "source": "en",
        "uid": "1",
        "status": "1",
        "translate": "0",
        "created": "1448942355",
        "changed": "1448942355"
      }
    }
joseph.olstad’s picture

This patch works great for us, now we are able to deploy newly created beans that have translation(s).

Many thanks to Sylus and a.milkovsky

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

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