diff --git a/src/Plugin/EntityReferenceSelection/ParagraphSelection.php b/src/Plugin/EntityReferenceSelection/ParagraphSelection.php index 9e08223..a28ee6f 100644 --- a/src/Plugin/EntityReferenceSelection/ParagraphSelection.php +++ b/src/Plugin/EntityReferenceSelection/ParagraphSelection.php @@ -55,7 +55,7 @@ class ParagraphSelection extends DefaultSelection { $form['negotate'] = [ '#type' => 'select', '#options' => [0 => 'Include', 1 => 'Exclude'], - '#title' => $this->t('"Choose allowed paragraph types'), + '#title' => $this->t('Choose paragraph types'), '#return_value' => 1, '#default_value' => isset($selection_handler_settings['negotate']) ? $selection_handler_settings['negotate'] : FALSE, ]; @@ -80,7 +80,7 @@ class ParagraphSelection extends DefaultSelection { 'id' => 'bundles', ], '#prefix' => '
' . $this->t('Paragraph types') . '
', - '#suffix' => '
' . $this->t('The paragraph types that are allowed to be created in this field. Select none to allow all paragraph types.') .'
', + '#suffix' => '
' . $this->t('Selection of paragraph types for this field. Select none to allow all paragraph types.') .'
', ]; $form['target_bundles_drag_drop']['#tabledrag'][] = [ diff --git a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php index 0a9f9e2..166f386 100644 --- a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php @@ -684,6 +684,10 @@ class ParagraphsWidget extends WidgetBase { if ($this->getSelectionHandlerSetting('target_bundles') !== NULL) { $bundles = array_intersect_key($bundles, $this->getSelectionHandlerSetting('target_bundles')); + if ($this->getSelectionHandlerSetting('negotate')) { + $bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($target_type); + $bundles = array_diff_key($bundles, $this->getSelectionHandlerSetting('target_bundles')); + } } // Support for the paragraphs reference type. diff --git a/src/Tests/Experimental/ParagraphsExperimentalConfigTest.php b/src/Tests/Experimental/ParagraphsExperimentalConfigTest.php index 6e99405..c0bf22e 100644 --- a/src/Tests/Experimental/ParagraphsExperimentalConfigTest.php +++ b/src/Tests/Experimental/ParagraphsExperimentalConfigTest.php @@ -158,4 +158,50 @@ class ParagraphsExperimentalConfigTest extends ParagraphsExperimentalTestBase { $this->assertNoOption('edit-fields-field-node-reference-type', 'paragraphs'); } + /** + * Test included paragraph types. + */ + public function testIncludedParagraphTypes() { + $this->loginAsAdmin(); + // Add a Paragraph content type and 2 Paragraphs types. + $this->addParagraphedContentType('paragraphed_test', 'paragraphs'); + $this->addParagraphsType('paragraph_type_test'); + $this->addParagraphsType('text'); + + $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs'); + $edit = [ + 'settings[handler_settings][negotate]' => 0, + 'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1, + ]; + $this->drupalPostForm(NULL, $edit, 'Save settings'); + $this->assertText('Saved paragraphs configuration.'); + + $this->drupalGet('node/add/paragraphed_test'); + $this->assertText('Add paragraph_type_test'); + $this->assertNoText('Add text'); + } + + /** + * Test excluded paragraph types. + */ + public function testExcludedParagraphTypes() { + $this->loginAsAdmin(); + // Add a Paragraph content type and 2 Paragraphs types. + $this->addParagraphedContentType('paragraphed_test', 'paragraphs'); + $this->addParagraphsType('paragraph_type_test'); + $this->addParagraphsType('text'); + + $this->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs'); + $edit = [ + 'settings[handler_settings][negotate]' => 1, + 'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1, + ]; + $this->drupalPostForm(NULL, $edit, 'Save settings'); + $this->assertText('Saved paragraphs configuration.'); + + $this->drupalGet('node/add/paragraphed_test'); + $this->assertText('Add paragraph_type_test'); + $this->assertNoText('Add text'); + } + }