Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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);
Comment | File | Size | Author |
---|---|---|---|
#2 | bean_translation_is_new-2576711-1.patch | 460 bytes | a.milkovsky |
Comments
Comment #2
a.milkovskyThere should be an additional logic in EntityTranslationBeanHandler to check if entity is new.
Comment #3
a.milkovskyComment #4
sylus CreditAttribution: sylus commentedThank 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:
Comment #5
joseph.olstadThis 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
Comment #7
DamienMcKennaCommitted. Thanks.