diff -u b/src/Tests/ParagraphsTranslationTest.php b/src/Tests/ParagraphsTranslationTest.php --- b/src/Tests/ParagraphsTranslationTest.php +++ b/src/Tests/ParagraphsTranslationTest.php @@ -1,7 +1,7 @@ drupalPostForm(NULL, NULL, t('Save and keep published (this translation)')); $this->assertText('Paragraphed article Title in english has been updated.'); - // Check. + // Create a new demo node adding a 'Text' paragraph with german langcode. $this->drupalGet('node/add/paragraphed_content_demo'); $edit = [ 'langcode[0][value]' => 'de', ]; $this->drupalPostForm(NULL, $edit, 'Add Text'); + // Check if the 'add more' and 'remove' buttons are displayed. $this->assertRaw('name="field_paragraphs_demo_0_remove"'); $this->assertRaw('name="field_paragraphs_demo_image_text_add_more"'); } only in patch2: unchanged: --- a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -295,7 +295,7 @@ class InlineParagraphsWidget extends WidgetBase { } // Hide the button when translating. - $button_access = $paragraphs_entity->access('delete') && $paragraphs_entity->language()->getId() == $paragraphs_entity->getUntranslated()->language()->getId(); + $button_access = !$this->isInTranslation($form_state, $items) && $paragraphs_entity->access('delete'); $links['remove_button'] = array( '#type' => 'submit', '#value' => t('Remove'), @@ -731,7 +731,7 @@ class InlineParagraphsWidget extends WidgetBase { // 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(); + $add_more_access = !$this->isInTranslation($form_state, $items); $elements['add_more'] = array( '#type' => 'container', '#theme_wrappers' => array('paragraphs_dropbutton_wrapper'), @@ -842,6 +842,26 @@ class InlineParagraphsWidget extends WidgetBase { } /** + * Checks whether the node is in translation. + * + * If the entity is new, then set the langcode from the language_select to + * the node source language. Return TRUE/FALSE whether the add / remove + * buttons should be displayed. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * @param \Drupal\Core\Field\FieldItemListInterface $items + * + * @return boolean + */ + protected function isInTranslation(FormStateInterface $form_state, FieldItemListInterface $items) { + if ($form_state->getFormObject()->getEntity()->isNew()) { + $form_state->set('langcode', $this->getCurrentLangcode($form_state, $items)); + return FALSE; + } + return TRUE; + } + + /** * {@inheritdoc} */ public static function addMoreAjax(array $form, FormStateInterface $form_state) {