diff --git a/modules/paragraphs_i18n/paragraphs_i18n.info b/modules/paragraphs_i18n/paragraphs_i18n.info index c2da534..6871f0f 100644 --- a/modules/paragraphs_i18n/paragraphs_i18n.info +++ b/modules/paragraphs_i18n/paragraphs_i18n.info @@ -1,8 +1,6 @@ name = Paragraphs - Internationalization -description = Allow paragraph bundles to be duplicate for translation. +description = Translation integration for paragraphs. core = 7.x package = Paragraphs dependencies[] = paragraphs -dependencies[] = replicate -dependencies[] = replicate_paragraphs diff --git a/modules/paragraphs_i18n/paragraphs_i18n.module b/modules/paragraphs_i18n/paragraphs_i18n.module index c849853..8a3f75d 100644 --- a/modules/paragraphs_i18n/paragraphs_i18n.module +++ b/modules/paragraphs_i18n/paragraphs_i18n.module @@ -1,26 +1,6 @@ &$item) { - if ($current_entity = paragraphs_field_get_entity($item)) { - $current_entity = replicate_clone_entity('paragraphs_item', $current_entity); - $current_entity->setHostEntity($entity_type, $source_entity, $langcode, FALSE); - $current_entity->save(TRUE); - $news_items[] = array( - 'value' => $current_entity->item_id, - 'revision_id' => $current_entity->revision_id, - ); - } - } - $items = $news_items; - } -} \ No newline at end of file diff --git a/paragraphs.module b/paragraphs.module index 973b785..9e132f4 100644 --- a/paragraphs.module +++ b/paragraphs.module @@ -731,6 +731,33 @@ function paragraphs_field_presave($host_entity_type, $host_entity, $field, $inst } } +/** + * Implements hook_field_insert(). + */ +function paragraphs_field_insert($host_entity_type, $host_entity, $field, $instance, $langcode, &$items) { + foreach ($items as &$item) { + if ($entity = paragraphs_field_get_entity($item)) { + if (!empty($host_entity->is_new) && empty($entity->is_new)) { + // If the host entity is new but we have a paragraph item that is not + // new, it means that its host is being cloned. Thus we need to clone + // the paragraph item entity as well. + $new_entity = clone $entity; + $new_entity->item_id = NULL; + $new_entity->revision_id = NULL; + $new_entity->is_new = TRUE; + $entity = $new_entity; + } + if (!empty($entity->is_new)) { + $entity->setHostEntity($host_entity_type, $host_entity, LANGUAGE_NONE, FALSE); + } + $entity->save(TRUE); + $item = array( + 'value' => $entity->item_id, + 'revision_id' => $entity->revision_id, + ); + } + } +} /** * Implements hook_field_update(). @@ -1313,26 +1340,6 @@ function paragraphs_field_attach_form($entity_type, $entity, &$form, &$form_stat } /** - * Implements hook_field_prepare_translation(). - * - * @see field_attach_prepare_translation() - */ -function paragraphs_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) { - if (!module_exists("paragraphs_i18n")) { - list($id, , ) = entity_extract_ids($entity_type, $entity); - - // field_attach_prepare_translation() copied the entity ids from the source, - // as we need a new entity for a new translation, we cannot reuse that. - // @todo clone existing paragraphs to new translation - if (empty($id)) { - $items = array(); - } - } else { - paragraphs_i18n_field_prepare_translation($entity_type, $entity, $field, $instance, $langcode, $items, $source_entity, $source_langcode); - } -} - -/** * Implements hook_features_api(). */ function paragraphs_features_api() {