[英]Using Fragment in Drupal 7 Form Redirect
我正在嘗試將網站管理員重定向到更新內容,因為它永遠不會被直接查看。 相反,我嘗試將它們鏈接到主頁的特定部分,但是在進行重定向時,fragment選項將被忽略。
function _content_redirect_to(&$form_state, $hash) {
$destination = drupal_get_destination();
if ($destination['destination'] != 'admin/content') {
$form_state['redirect'] = array(
'<front>',
array(
'query' => array(),
'fragment' => 'whatever',
'absolute' => TRUE,
),
);
}
}
function _content_redirect_location($form, &$form_state) {
_content_redirect_to($form_state, 'locations');
}
function content_redirect_form_alter(&$form, &$form_state, $form_id) {
$link = l('test link', '<front>', array(
'fragment' => 'locations'
));
drupal_set_message($link); // Works just fine.
switch ($form_id) {
case 'location_node_form':
$form['actions']['submit']['#submit'][] = '_content_redirect_location';
break;
}
}
當我在更新時直接調用drupal_goto時,也會發生同樣的事情。
function content_redirect_node_update($node) {
if ($node->type == 'location') {
drupal_goto(
'<front>', array(
'fragment' => 'locations'
)
);
}
}
我無法在其他地方找到有關此信息。
正確的方法是:
$form_state['redirect'] = array('<front>', array('fragment' => 'location'));
我知道這不是一個完美的解決方案,但是請嘗試以下操作:
$form['#action'] = url($_GET['q'], array('query' => array('destination' => 'DESIRED_LOCATION')));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.