Loading src/Form/ContactFormCloneForm.php +12 −8 Original line number Diff line number Diff line Loading @@ -118,17 +118,21 @@ class ContactFormCloneForm extends ContactFormEditForm { // Clone the entity form display. $display = EntityFormDisplay::load('contact_message.' . $original_id . '.default'); if ($display) { EntityFormDisplay::create([ 'bundle' => $contact_form->id(), 'uuid' => NULL, ] + $display->toArray())->save(); } // Clone the entity view display. $display = EntityViewDisplay::load('contact_message.' . $original_id . '.default'); if ($display) { EntityViewDisplay::create([ 'bundle' => $contact_form->id(), 'uuid' => NULL, ] + $display->toArray())->save(); } // Redirect and show messge. $form_state->setRedirect('entity.contact_form.edit_form', ['contact_form' => $contact_form->id()]); Loading tests/src/Functional/ContactStorageTest.php +24 −5 Original line number Diff line number Diff line Loading @@ -87,6 +87,13 @@ class ContactStorageTest extends ContactStorageTestBase { $this->addContactForm('test_id', 'test_label', $mail, TRUE); $this->assertText('Contact form test_label has been added.'); // Ensure that new contact form can be cloned. $this->cloneContactForm('test_id', 'test_id_cloned'); $original_form = ContactForm::load('test_id'); $cloned_form = ContactForm::load('test_id_cloned'); $this->assertTrue($cloned_form->uuid()); $this->assertNotEquals($original_form->uuid(), $cloned_form->uuid()); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access site-wide contact form']); $this->drupalLogout(); Loading Loading @@ -248,11 +255,7 @@ class ContactStorageTest extends ContactStorageTestBase { // Test clone functionality - add field to existing form. $this->fieldUIAddNewField('admin/structure/contact/manage/test_id', 'text_field', 'Text field', 'text'); // Then clone it. $this->drupalGet('admin/structure/contact/manage/test_id/clone'); $this->drupalPostForm(NULL, [ 'id' => 'test_id_2', 'label' => 'Cloned', ], t('Clone')); $this->cloneContactForm('test_id', 'test_id_2'); $edit = [ 'subject[0][value]' => 'Test subject', Loading Loading @@ -478,4 +481,20 @@ class ContactStorageTest extends ContactStorageTestBase { } /** * Clone form. * * @param string $original_form_id * The original form machine name. * @param string $clone_form_id * The new form machine name. */ protected function cloneContactForm($original_form_id, $clone_form_id) { $this->drupalGet("admin/structure/contact/manage/$original_form_id/clone"); $this->drupalPostForm(NULL, [ 'id' => $clone_form_id, 'label' => 'Cloned', ], t('Clone')); } } Loading
src/Form/ContactFormCloneForm.php +12 −8 Original line number Diff line number Diff line Loading @@ -118,17 +118,21 @@ class ContactFormCloneForm extends ContactFormEditForm { // Clone the entity form display. $display = EntityFormDisplay::load('contact_message.' . $original_id . '.default'); if ($display) { EntityFormDisplay::create([ 'bundle' => $contact_form->id(), 'uuid' => NULL, ] + $display->toArray())->save(); } // Clone the entity view display. $display = EntityViewDisplay::load('contact_message.' . $original_id . '.default'); if ($display) { EntityViewDisplay::create([ 'bundle' => $contact_form->id(), 'uuid' => NULL, ] + $display->toArray())->save(); } // Redirect and show messge. $form_state->setRedirect('entity.contact_form.edit_form', ['contact_form' => $contact_form->id()]); Loading
tests/src/Functional/ContactStorageTest.php +24 −5 Original line number Diff line number Diff line Loading @@ -87,6 +87,13 @@ class ContactStorageTest extends ContactStorageTestBase { $this->addContactForm('test_id', 'test_label', $mail, TRUE); $this->assertText('Contact form test_label has been added.'); // Ensure that new contact form can be cloned. $this->cloneContactForm('test_id', 'test_id_cloned'); $original_form = ContactForm::load('test_id'); $cloned_form = ContactForm::load('test_id_cloned'); $this->assertTrue($cloned_form->uuid()); $this->assertNotEquals($original_form->uuid(), $cloned_form->uuid()); // Ensure that anonymous can submit site-wide contact form. user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access site-wide contact form']); $this->drupalLogout(); Loading Loading @@ -248,11 +255,7 @@ class ContactStorageTest extends ContactStorageTestBase { // Test clone functionality - add field to existing form. $this->fieldUIAddNewField('admin/structure/contact/manage/test_id', 'text_field', 'Text field', 'text'); // Then clone it. $this->drupalGet('admin/structure/contact/manage/test_id/clone'); $this->drupalPostForm(NULL, [ 'id' => 'test_id_2', 'label' => 'Cloned', ], t('Clone')); $this->cloneContactForm('test_id', 'test_id_2'); $edit = [ 'subject[0][value]' => 'Test subject', Loading Loading @@ -478,4 +481,20 @@ class ContactStorageTest extends ContactStorageTestBase { } /** * Clone form. * * @param string $original_form_id * The original form machine name. * @param string $clone_form_id * The new form machine name. */ protected function cloneContactForm($original_form_id, $clone_form_id) { $this->drupalGet("admin/structure/contact/manage/$original_form_id/clone"); $this->drupalPostForm(NULL, [ 'id' => $clone_form_id, 'label' => 'Cloned', ], t('Clone')); } }