我一直在争取与此很长一段时间,但后来我发现简单的解决方案.
我需要重定向到新的批量处理页面点击所以这里提交按钮后右侧是一个解决方案
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirectUrl(Url::fromUri())
$identity = isset($form_state->getTriggeringElement()['#identity']) ? $form_state->getTriggeringElement()['#identity'] : 'unknown';
switch ($identity) {
case static::BTN_UPDATE;
$batch = [
'title' => t('Updating'),
'operations' => [
array('sfo_common_batch_callbacks__taxonomy_update_cache_process', [[]]),
],
'finished' => 'sfo_common_batch_callbacks__taxonomy_update_cache_finished',
'file' => drupal_get_path('module', 'sfo_common') . '/include/batch/sfo_common.taxonomy_cache.inc',
];
batch_set($batch);
$request = batch_process(static::URL_REDIRECT);
return $request->send();
break;
default:
drupal_set_message(t('Incorrect operation'));
break;
}
}
这是我发现用例. 但这只是批量的伟大工程. 如果需要的形式后重定向提交它也可能使用
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect(taxonomy.vocabulary.collection); // Here need to pass route name from *.routes.yml file
//But if you need to redirect to custom url
$form_state->setRedirectUrl(Url::fromUri('http://google.com')); // Need to pass Drupal\Core\Url object here
}
其他的方法来重定向 https://www.drupal.org/node/2023537
![]()
