diff --git a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php index bad9de5..6348939 100644 --- a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -730,7 +730,6 @@ 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->addMoreAccess($items, $form_state); $elements['add_more'] = array( '#type' => 'container', @@ -838,14 +837,13 @@ class InlineParagraphsWidget extends WidgetBase { * @return string */ protected function getCurrentLangcode(FormStateInterface $form_state, FieldItemListInterface $items) { - // The from and the parent entity have a locked language + // The form and the parent entity have a locked language // (\Drupal\Core\Language::LANGCODE_NOT_SPECIFIED is most cases). Use the // current interface language instead. - if ($form_state->get('langcode') == $items->getEntity()->language()->getId()) { - if ($items->getEntity()->language()->isLocked()) { - return \Drupal::languageManager()->getCurrentLanguage()->getId(); - } + if ($form_state->get('langcode') && \Drupal::languageManager()->getLanguage($form_state->get('langcode'))->isLocked()){ + return \Drupal::languageManager()->getCurrentLanguage()->getId(); } + return $form_state->get('langcode') ?: $items->getEntity()->language()->getId(); } @@ -1115,6 +1113,7 @@ class InlineParagraphsWidget extends WidgetBase { * @return bool */ protected function addMoreAccess(FieldItemListInterface $items, FormStateInterface $form_state) { + // Hide the button when translating. if (!$items->getEntity()->getEntityType()->isTranslatable()) { return TRUE; } diff --git a/src/Tests/ParagraphsTranslationTest.php b/src/Tests/ParagraphsTranslationTest.php index 4075edd..ecb1398 100644 --- a/src/Tests/ParagraphsTranslationTest.php +++ b/src/Tests/ParagraphsTranslationTest.php @@ -86,6 +86,12 @@ class ParagraphsTranslationTest extends WebTestBase { $this->drupalPostForm(NULL, $edit, t('Save and keep published')); $this->assertNoText(t('Example published and unpublished')); + //Add paragraphed content with untranslatable language + $this->drupalGet('node/add/paragraphed_content_demo'); + $edit = array('langcode[0][value]' => 'und'); + $this->drupalPostForm(NULL, $edit, t('Add Text + Image')); + $this->assertResponse(200); + // Add paragraphed content. $this->drupalGet('node/add/paragraphed_content_demo'); $this->drupalPostForm(NULL, NULL, t('Add Text + Image'));