在创建新页面时如何防止 Drupal 8 重定向到该页面?
How do you prevent Drupal 8 from redirecting to the page when a new page has been created?
当您在 Drupal 8 中创建新页面时,它会将用户重定向到站点上的该页面,我希望它能重定向回管理界面的内容部分。
有办法吗?
您需要创建自定义模块并使用
您首先要检查它是什么形式,然后像这样添加自定义提交回调
function your_module_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// test you are altering the correct form so wrap the below in an IF
$form['actions']['submit']['#submit'][] = '_your_module_custom_redirect';
}
function _your_module_custom_redirect($form, FormStateInterface $form_state) {
$form_state->setRedirect('your route name');
}
或者可能使用 hook_ENTITY_TYPE_insert(),因为我认为 hook_form_alter 将 运行 无论验证如何,但我不是 100%
当您在 Drupal 8 中创建新页面时,它会将用户重定向到站点上的该页面,我希望它能重定向回管理界面的内容部分。
有办法吗?
您需要创建自定义模块并使用
您首先要检查它是什么形式,然后像这样添加自定义提交回调
function your_module_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// test you are altering the correct form so wrap the below in an IF
$form['actions']['submit']['#submit'][] = '_your_module_custom_redirect';
}
function _your_module_custom_redirect($form, FormStateInterface $form_state) {
$form_state->setRedirect('your route name');
}
或者可能使用 hook_ENTITY_TYPE_insert(),因为我认为 hook_form_alter 将 运行 无论验证如何,但我不是 100%