目标:打印/转储要调试的$formState值
我正在修改一个表单,其功能起作用:
$form['elements']['location']['deparment']['#ajax'] = [
'callback' => 'myAjaxCallback',
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => t('Verifying entry...'),
]
];但是我想要的是能够打印出$formState在myAjaxCallback中
function myAjaxCallback(array &$form, FormStateInterface $formState){
$response = new AjaxResponse();
print_r($formState); //I've tried, with memory_limit=-1 . it just hangs
dump($formState); //gives me File upload exceeds. This comes from issue with using dump in ajax
https://drupal.stackexchange.com/questions/250078/ajax-submission-leads-to-an-unrecoverable-error-occurred-the-uploaded-file-l
return $response
}我还读过https://www.drupal.org/docs/drupal-apis/javascript-api/ajax-forms并尝试过调试AJAX回调函数,其中包括:
$response = new AjaxResponse();
$debugOut = @Kint::dump($formState); //but this uses dump too, which gives me ajax errors所以dd($formState->getValues());有点工作。这就是它展示给我的。所以,正如你所看到的,我现在可以看到变量。这不是最好的,而是可读的。

然而,如果我去/webform?ajax_form=1,它甚至是不可读的。

为了能够调试变量$formState,我的想法已经用完了。
发布于 2020-08-27 00:38:41
@sonfd Xdebug帮助打印出漂亮的值。不再有print_r()或kint()错误。

https://drupal.stackexchange.com/questions/296278
复制相似问题