Tests the validation of paragraphs referencing library items.
public function testLibraryReferencingParagraphValidation() {
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
'administer paragraphs library',
]);
$paragraph_type = 'text';
$this
->addParagraphsType($paragraph_type);
static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
// Add a library item with paragraphs type "Text".
$this
->drupalGet('admin/content/paragraphs');
$this
->clickLink('Add library item');
$this
->submitForm([], 'paragraphs_text_add_more');
$edit = [
'label[0][value]' => 'reusable paragraph label',
'paragraphs[0][subform][field_text][0][value]' => 'reusable_text',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Paragraph reusable paragraph label has been created.');
// Create a node with a "From library" paragraph referencing the library
// item.
$this
->drupalGet('node/add/paragraphed_test');
$this
->submitForm([], 'field_paragraphs_from_library_add_more');
$edit = [
'title[0][value]' => 'library_test',
'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 'reusable paragraph label',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test library_test has been created.');
// Disallow the paragraphs type "Text" for the used content type.
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
$edit = [
'settings[handler_settings][negate]' => '0',
'settings[handler_settings][target_bundles_drag_drop][from_library][enabled]' => '1',
'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => FALSE,
];
$this
->submitForm($edit, 'Save settings');
$this
->assertSession()
->pageTextContains('Saved field_paragraphs configuration.');
// Check that the node now fails validation.
$node = $this
->getNodeByTitle('library_test');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([], 'Save');
$this
->assertSession()
->addressEquals('node/' . $node
->id() . '/edit');
$this
->assertSession()
->pageTextContains('The Reusable paragraph field cannot contain a text paragraph, because the parent field_paragraphs field disallows it.');
}