diff --git a/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php b/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php index 7a8e0fc..69f12a3 100644 --- a/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ b/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -22,9 +22,6 @@ /** * Plugin implementation of the 'entity_reference paragraphs' widget. * - * We hide add / remove buttons when translating to avoid accidental loss of - * data because these actions effect all languages. - * * @FieldWidget( * id = "entity_reference_paragraphs", * label = @Translation("Paragraphs"), @@ -208,18 +205,24 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen } if ($paragraphs_entity) { - // If target translation is not yet available, populate it with data from the original paragraph. + // If there is no paragraph entity in this language create one and duplicate the fields. $target_langcode = $this->getCurrentLangcode($form_state, $items); - if ($paragraphs_entity->language()->getId() != $target_langcode && !$paragraphs_entity->hasTranslation($target_langcode)) { - $paragraphs_entity->addTranslation($target_langcode, $paragraphs_entity->toArray()); - } + if ($paragraphs_entity->language()->getId() != $target_langcode) { + $values = $paragraphs_entity->toArray(); + $entity_type = $entity_manager->getDefinition($target_type); + $bundle_key = $entity_type->getKey('bundle'); + $new_values = array( + $bundle_key => $paragraphs_entity->bundle(), + 'langcode' => $target_langcode, + ); - // Initiate the paragraph with the correct translation. - if ($paragraphs_entity->hasTranslation($this->getCurrentLangcode($form_state, $items))) { - $paragraphs_entity = $paragraphs_entity->getTranslation($this->getCurrentLangcode($form_state, $items)); - } else { - $paragraphs_entity = $paragraphs_entity->addTranslation($this->getCurrentLangcode($form_state, $items)); - } + foreach ($paragraphs_entity->getFieldDefinitions() as $key => $value) { + if (get_class($value) == 'Drupal\field\Entity\FieldConfig') { + $new_values[$key] = $values[$key][0]; + } + } + $paragraphs_entity = $entity_manager->getStorage($target_type)->create($new_values); + } $element_parents = $parents; $element_parents[] = $field_name; @@ -295,8 +298,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ); } - // Hide the button when translating. - $button_access = $paragraphs_entity->access('delete') && $paragraphs_entity->language()->getId() == $paragraphs_entity->getUntranslated()->language()->getId(); $links['remove_button'] = array( '#type' => 'submit', '#value' => t('Remove'), @@ -310,7 +311,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen 'wrapper' => $widget_state['ajax_wrapper_id'], 'effect' => 'fade', ), - '#access' => $button_access, '#prefix' => '
  • ', '#suffix' => '
  • ', ); @@ -732,12 +732,9 @@ public function formMultipleElements(FieldItemListInterface $items, array &$form // Add 'add more' button, if not working with a programmed form. if (($real_item_count < $cardinality || $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) && !$form_state->isProgrammed()) { - // Hide the button when translating. - $add_more_access = $this->getCurrentLangcode($form_state, $items) == $items->getEntity()->getUntranslated()->language()->getId(); $elements['add_more'] = array( '#type' => 'container', '#theme_wrappers' => array('paragraphs_dropbutton_wrapper'), - '#access' => $add_more_access, ); if (count($access_options)) {