When trying to merge references, I get the following exception. I tried 4.1.x Dev and 4.2.x Dev.
Exception: Serialization of 'Closure' is not allowed in serialize() (line 14 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).
Drupal\Component\Serialization\PhpSerialize::encode(Array) (Line: 111)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->doSetWithExpire('form-nAeWq3krW2p2NT2wBfKoGVH3cpY5Hb41Cb2GtnQfVDU', Array, 21600) (Line: 127)
Drupal\Core\KeyValueStore\DatabaseStorageExpirable->setWithExpire('form-nAeWq3krW2p2NT2wBfKoGVH3cpY5Hb41Cb2GtnQfVDU', Array, 21600) (Line: 193)
Drupal\Core\Form\FormCache->setCache('form-nAeWq3krW2p2NT2wBfKoGVH3cpY5Hb41Cb2GtnQfVDU', Array, Object) (Line: 463)
Drupal\Core\Form\FormBuilder->setCache('form-nAeWq3krW2p2NT2wBfKoGVH3cpY5Hb41Cb2GtnQfVDU', Array, Object) (Line: 441)
Drupal\Core\Form\FormBuilder->rebuildForm('mergefilereferences', Object, Array) (Line: 633)
Drupal\Core\Form\FormBuilder->processForm('mergefilereferences', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
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}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
The problem is that these closures cannot be serialized. Because the form is a multi-step form, the form array needs to be serialized. That's why there's no errors on the other reports.
$form['actions']['add'] = [
'#type' => 'submit',
'#value' => $this->t('Next step'),
'#validate' => [
$this::validateForm(...),
],
'#submit' => [
$this::submitMergePreConfirm(...),
],
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->getConfirmText(),
'#button_type' => 'primary',
'#submit' => [
$this::confirmSubmissionHandlerFileMerge(...),
],
];
Proposed resolution
Use the serializable format for callables:
$form['actions']['add'] = [
'#type' => 'submit',
'#value' => $this->t('Next step'),
'#validate' => [
[$this, 'validateForm'],
],
'#submit' => [
[$this, 'submitMergePreConfirm'],
],
];
[$this, 'confirmSubmissionHandlerFileMerge'],