diff --git a/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
index 16f9701..bcaf788 100644
--- a/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
+++ b/modules/paragraphs_demo/src/Tests/ParagraphsDemoTest.php
@@ -129,7 +129,7 @@ class ParagraphsDemoTest extends WebTestBase {
$this->assertNoFieldChecked('edit-settings-handler-settings-target-bundles-drag-drop-text-enabled');
$this->drupalGet('node/add/paragraphed_content_demo');
- $this->assertRaw('Paragraphs', 'Field name is present on the page.');
+ $this->assertRaw('
Paragraphs
', 'Field name is present on the page.');
$this->drupalPostForm(NULL, NULL, t('Add Text'));
$this->assertNoRaw('Paragraphs', 'Field name for empty field is not present on the page.');
$this->assertRaw('Paragraphs
', 'Field name appears in the table header.');
diff --git a/paragraphs.module b/paragraphs.module
index cfd0fc6..037f924 100644
--- a/paragraphs.module
+++ b/paragraphs.module
@@ -341,7 +341,12 @@ function paragraphs_preprocess_field_multiple_value_form(&$variables) {
unset($variables['table']['#rows'][0]);
}
}
- if (isset($variables['element']['#allow_reference_changes']) && !$variables['element']['#allow_reference_changes']) {
+
+ // Remove the drag handler if we are translating, if the field's cardinality
+ // is 1 or if there are no paragraphs added. Passing through this will not
+ // only remove the drag handler but also the order column that is empty when
+ // no paragraphs are added and when the field is single value.
+ if ((isset($variables['element']['#allow_reference_changes']) && !$variables['element']['#allow_reference_changes']) || $variables['element']['#cardinality'] == 1 || count($variables['table']['#rows']) == 0) {
if (isset($variables['table']['#tabledrag'])) {
// Remove the tabledrag.
unset($variables['table']['#tabledrag']);
diff --git a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
index 82ba514..2039580 100644
--- a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -1000,45 +1000,16 @@ class ParagraphsWidget extends WidgetBase {
'#max_delta' => $max - 1,
];
- if ($this->realItemCount > 0) {
- $elements += array(
- '#theme' => 'field_multiple_value_form',
- '#cardinality_multiple' => $is_multiple,
- '#title' => $field_title,
- '#description' => $description,
- );
-
- }
- else {
- $classes = $this->fieldDefinition->isRequired() ? ['form-required'] : [];
- $elements += [
- '#type' => 'container',
- '#theme_wrappers' => ['container'],
- '#cardinality_multiple' => TRUE,
- 'title' => [
- '#type' => 'html_tag',
- '#tag' => 'strong',
- '#value' => $field_title,
- '#attributes' => ['class' => $classes],
- ],
- 'text' => [
- '#type' => 'container',
- 'value' => [
- '#markup' => $this->t('No @title added yet.', ['@title' => $this->getSetting('title')]),
- '#prefix' => '',
- '#suffix' => '',
- ]
- ],
- ];
-
- if ($description) {
- $elements['description'] = [
- '#type' => 'container',
- 'value' => ['#markup' => $description],
- '#attributes' => ['class' => ['description']],
- ];
- }
- }
+ $elements += [
+ '#theme' => 'field_multiple_value_form',
+ '#field_name' => $field_name,
+ '#cardinality' => $cardinality,
+ '#cardinality_multiple' => TRUE,
+ '#required' => $this->fieldDefinition->isRequired(),
+ '#title' => $field_title,
+ '#description' => $description,
+ '#max_delta' => $max - 1,
+ ];
$host = $items->getEntity();
$this->initIsTranslating($form_state, $host);
diff --git a/src/Tests/Experimental/ParagraphsExperimentalAddModesTest.php b/src/Tests/Experimental/ParagraphsExperimentalAddModesTest.php
index 7ee5c5e..2fa86f4 100644
--- a/src/Tests/Experimental/ParagraphsExperimentalAddModesTest.php
+++ b/src/Tests/Experimental/ParagraphsExperimentalAddModesTest.php
@@ -183,7 +183,10 @@ class ParagraphsExperimentalAddModesTest extends ParagraphsExperimentalTestBase
// Check if is Text + Image is added as default paragraph type.
$this->drupalGet('node/add/paragraphed_test');
- $this->assertText('No Paragraph added yet.');
+ $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody');
+ $header = $this->xpath('//table[@id="paragraphs-values"]/thead');
+ $this->assertEqual($elements, []);
+ $this->assertNotEqual($header, []);
// Check if default type is created only for new host
$this->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', 'text_image');
@@ -191,7 +194,10 @@ class ParagraphsExperimentalAddModesTest extends ParagraphsExperimentalTestBase
$edit = ['title[0][value]' => 'New Host'];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('node/1/edit');
- $this->assertText('No Paragraph added yet.');
+ $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody');
+ $header = $this->xpath('//table[@id="paragraphs-values"]/thead');
+ $this->assertEqual($elements, []);
+ $this->assertNotEqual($header, []);
}
/**
@@ -215,12 +221,18 @@ class ParagraphsExperimentalAddModesTest extends ParagraphsExperimentalTestBase
// Check that when only one paragraph type is allowed in a content type,
// one instance is automatically added in the 'Add content' dialogue.
$this->drupalGet('node/add/paragraphed_test');
- $this->assertNoText('No Paragraph added yet.');
+ $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody');
+ $header = $this->xpath('//table[@id="paragraphs-values"]/thead');
+ $this->assertNotEqual($elements, []);
+ $this->assertNotEqual($header, []);
// Check that no paragraph type is automatically added, if the defaut
// setting was set to '- None -'.
$this->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', '_none');
$this->drupalGet('node/add/paragraphed_test');
- $this->assertText('No Paragraph added yet.');
+ $elements = $this->xpath('//table[@id="paragraphs-values"]/tbody');
+ $header = $this->xpath('//table[@id="paragraphs-values"]/thead');
+ $this->assertEqual($elements, []);
+ $this->assertNotEqual($header, []);
}
}
diff --git a/src/Tests/Experimental/ParagraphsExperimentalAdministrationTest.php b/src/Tests/Experimental/ParagraphsExperimentalAdministrationTest.php
index 696e166..03598ca 100644
--- a/src/Tests/Experimental/ParagraphsExperimentalAdministrationTest.php
+++ b/src/Tests/Experimental/ParagraphsExperimentalAdministrationTest.php
@@ -535,10 +535,17 @@ class ParagraphsExperimentalAdministrationTest extends ParagraphsExperimentalTes
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertText('choke test has been updated.');
+ $this->drupalGet('admin/structure/types/manage/article/fields');
+ $this->clickLink('Edit');
+ $this->drupalPostForm(NULL, ['description' => 'This is the description of the field.'], 'Save settings');
// Verify that the text displayed is correct when no paragraph has been
// added yet.
$this->drupalGet('node/add/article');
- $this->assertText('No Paragraph added yet.');
+ $this->assertText('This is the description of the field.');
+ $elements = $this->xpath('//table[@id="field-paragraphs-values"]/tbody');
+ $header = $this->xpath('//table[@id="field-paragraphs-values"]/thead');
+ $this->assertEqual($elements, []);
+ $this->assertNotEqual($header, []);
$this->drupalGet('admin/content/files');
$this->clickLink('1 place');
diff --git a/src/Tests/Experimental/ParagraphsExperimentalContactTest.php b/src/Tests/Experimental/ParagraphsExperimentalContactTest.php
index 30133c9..4bf2e28 100644
--- a/src/Tests/Experimental/ParagraphsExperimentalContactTest.php
+++ b/src/Tests/Experimental/ParagraphsExperimentalContactTest.php
@@ -43,6 +43,9 @@ class ParagraphsExperimentalContactTest extends ParagraphsExperimentalTestBase {
// Check that the paragraph is displayed.
$this->assertText('paragraphs_contact');
$this->drupalPostAjaxForm(NULL, [], 'paragraphs_0_remove');
- $this->assertText('No Paragraph added yet.');
+ $elements = $this->xpath('//table[starts-with(@id, :id)]/tbody', [':id' => 'paragraphs-values']);
+ $header = $this->xpath('//table[starts-with(@id, :id)]/thead', [':id' => 'paragraphs-values']);
+ $this->assertEqual($elements, []);
+ $this->assertNotEqual($header, []);
}
}
diff --git a/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php b/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php
index 91bc7ad..c1c0e55 100644
--- a/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php
+++ b/tests/src/FunctionalJavascript/ParagraphsExperimentalAddWidgetTest.php
@@ -130,7 +130,7 @@ class ParagraphsExperimentalAddWidgetTest extends JavascriptTestBase {
$this->assertContains($icon_two->getFilename(), $button_two->getAttribute('style'));
// Find the add button in the nested paragraph with xpath.
- $element = $this->xpath('//div[contains(@class, "form-wrapper")]/div[contains(@class, "paragraph-type-add-modal")]/input');
+ $element = $this->xpath('//div[contains(@class, "form-item")]/div/div[contains(@class, "paragraph-type-add-modal")]/input');
$element[0]->click();
$this->assertSession()->assertWaitOnAjaxRequest();