2011-10-07 69 views
2

我試圖將網站管理員從內容更新重定向,因爲它永遠不會被直接查看。相反,我嘗試將它們鏈接到主頁的特定部分,但在重定向發生時,片段選項被忽略。在Drupal 7表單重定向中使用片段

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' 
      ) 
     ); 
    } 
} 

我還找不到這方面的信息。

回答

0

我知道這不是一個完美的解決方案,但嘗試這個辦法:

$form['#action'] = url($_GET['q'], array('query' => array('destination' => 'DESIRED_LOCATION'))); 
0

做到這一點,正確的方法是:

$form_state['redirect'] = array('<front>', array('fragment' => 'location'));