在drupal7表单重定向中使用Fragment


Using Fragment in Drupal 7 Form Redirect

我试图重定向网站管理员远离更新内容,因为它永远不会被直接查看。相反,我试图将它们链接到主页的特定部分,然而,当重定向发生时,片段选项被忽略。

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

当我在update上直接调用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')));