2011-10-07 70 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'));