Skip to content
Snippets Groups Projects
Commit 0deade82 authored by Justin Toupin's avatar Justin Toupin
Browse files

Fixes issue with form parents and adds tests

parent 4ab840ff
No related branches found
No related tags found
2 merge requests!103Issue #3295875: Add a new dedicated permission for Layout paragraphs configurations,!89Fixes issue with form parents and adds tests
......@@ -174,6 +174,10 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase {
$filtered_values = $this->filterBehaviorFormSubmitValues($paragraph, $form, $form_state);
$plugin_instance = $this->layoutPluginManager->createInstance($form_state->getValue('layout'), $form_state->getValue('config') ?? []);
if ($plugin_form = $this->getLayoutPluginForm($plugin_instance)) {
// Add default #parents array to prevent form errors.
// @see https://www.drupal.org/project/layout_paragraphs/issues/3291180
$form['config'] += ['#parents' => []];
$form += ['#parents' => []];
$subform_state = SubformState::createForSubform($form['config'], $form, $form_state);
$plugin_form->submitConfigurationForm($form['config'], $subform_state);
$filtered_values['config'] = $plugin_form->getConfiguration();
......
<?php
namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
/**
* Tests basic compatibility with default paragraphs form widget.
*
* @group layout_paragraphs
*/
class ParagraphsWidgetCompatibilityTest extends WebDriverTestBase {
use ParagraphsTestBaseTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'layout_paragraphs',
'paragraphs',
'node',
'field',
'field_ui',
'block',
'paragraphs_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'claro';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->addParagraphsType('section');
$this->addFieldtoParagraphType('section', 'field_text', 'text');
$user = $this->drupalCreateUser([
'administer site configuration',
'administer node fields',
'administer node display',
'administer node form display',
'administer paragraphs types',
]);
$this->drupalLogin($user);
// Enable Layout Paragraphs behavior for section paragraph type.
$this->drupalGet('admin/structure/paragraphs_type/section');
$this->submitForm([
'behavior_plugins[layout_paragraphs][enabled]' => TRUE,
'behavior_plugins[layout_paragraphs][settings][available_layouts][]' => [
'layout_onecol',
'layout_twocol',
'layout_threecol_25_50_25',
'layout_threecol_33_34_33',
],
], 'Save');
$this->assertSession()->pageTextContains('Saved the section Paragraphs type.');
$this->drupalGet('admin/structure/paragraphs_type/section');
$this->addParagraphedContentType('page', 'field_content');
$this->drupalGet('admin/structure/types/manage/page/fields/node.page.field_content');
$this->submitForm([
'settings[handler_settings][negate]' => '1',
], 'Save settings');
$this->drupalGet('admin/structure/types/manage/page/form-display');
$page = $this->getSession()->getPage();
$btn = $page->find('css', '#edit-fields-field-content-settings-edit');
$btn->click();
$this->assertSession()->assertWaitOnAjaxRequest();
$page->selectFieldOption('fields[field_content][settings_edit_form][settings][default_paragraph_type]', 'section');
$this->submitForm([], 'Save');
$this->drupalLogout();
}
/**
* Tests that adding a new page works without errors.
*/
public function testAddPage() {
$user = $this->drupalCreateUser([
'create page content',
'edit own page content',
'edit behavior plugin settings',
]);
$this->drupalLogin($user);
$this->drupalGet('node/add/page');
$this->submitForm([
'title[0][value]' => 'Node title',
], 'Save');
$this->assertSession()->pageTextNotContains('The website encountered an unexpected error. Please try again later.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment