The clone does appear to be successful, but:
The website encountered an unexpected error. Please try again later.
Error: Call to a member function toArray() on null in Drupal\contact_storage\Form\ContactFormCloneForm->save() (line 131 of modules/contrib/contact_storage/src/Form/ContactFormCloneForm.php).
Drupal\contact_storage\Form\ContactFormCloneForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('contact_form_clone_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('contact_form_clone_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comments
Comment #2
znak commentedComment #3
jibranThis works just fine for me.
Comment #4
johnpitcairn commentedThanks, it's working here now too. Might have been interacting with something else. Closing.
Comment #5
svetoslav.dragoev commentedHi,
We are currently using Contact Storage module, version: '8.x-1.0-beta9' and we ended up with the same error as described above. I had a little digging and found core of the problem.
When you create a Contact form initially, if you don't go through Manage form display and press Save, this configuration never gets stored as a record in the Database - key_value table, example:
collection: config.entity.key_store.entity_form_display; name: uuid:3305cf92-35d8-4085-86ce-38e96f733b31; ....Because of that problems emerged when you use the Contact storage module to clone an entity, a form.
So when you create a new form, just Insert - Save and that's it, then you start cloning, you end up with the following error:
Fatal error: Call to a member function toArray() on a non-object in /home/duwcy/www/modules/contact_storage/src/Form/ContactFormCloneForm.php on line 124....Which is caused of the fact that inside ContactFormCloneForm file - save method is executing the following:
Important part is here:
$display->toArray())->save()So when Form Display is not being saved, because we haven't opened that form to press the button and trigger the insert, it does not exist in the database and naturally not being found. That leaves $display variable empty, but not validated before being used as an object, which causes a fatal error.
Even if the reason is in the core for not saving Form Display data, I think a fix should be applied here, a simple validation should do the work:
We've already found that even when the error is triggered, all other data is being copied, so the form is working, meaning it could get along even without the `EntityFormDisplay`, so we can continue the process and don't throw errors or revert it.
And one more thing in this same file and same functionality is duplicated:
As you can see, it's absolutely the same. Line 119 - 131: http://cgit.drupalcode.org/contact_storage/tree/src/Form/ContactFormClon....
Best regards,
Svetoslav
Comment #6
vacho commented@svetoslav.dragoev great job debugging the issue. I founded the same problem for 8.x-1.0 version.
I fix simply loading default configurations for this files:
core.entity_form_display.contact_message.contact.default.yml
core.entity_view_display.contact_message.contact.default.yml
I am thinking that maybe it is a core contact module issue too.
Comment #7
sinn commented> As you can see, it's absolutely the same. Line 119 - 131:
No, lines are different. In the beginning we create EntityFormDisplay instance and then EntityViewDisplay instance.
> I am thinking that maybe it is a core contact module issue too.
Config entities are created without view or form display configurations by default (it is true and for Vocabulary entity, for example). Based on that I think we should just add condition to check whether configurations exist or not during cloning.
Refactored test that shows the issue is attached. The main issue here was that code below creates entity view and entity form display configurations that by default is absent:
$this->fieldUIAddNewField('admin/structure/contact/manage/test_id', 'text_field', 'Text field', 'text');Comment #9
sinn commentedPlease review the solution.
Comment #10
andras_szilagyi commented#9 solved the issue for me
Comment #12
berdirCommitted.