简体   繁体   English

在Drupal 7表单重定向中使用片段

[英]Using Fragment in Drupal 7 Form Redirect

I'm trying to redirect site admins away from content on update as it will never be directly viewed. 我正在尝试将网站管理员重定向到更新内容,因为它永远不会被直接查看。 Instead I am trying to link them to a specific section of the home page however while the redirect is occurring, the fragment option is being ignored. 相反,我尝试将它们链接到主页的特定部分,但是在进行重定向时,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;
    }
}

The same thing happens when I call drupal_goto directly on update. 当我在更新时直接调用drupal_goto时,也会发生同样的事情。

function content_redirect_node_update($node) {
    if ($node->type == 'location') {
        drupal_goto(
            '<front>', array(
                'fragment' => 'locations'
            )
        );
    }
}

I haven't been able to find information on this else where. 我无法在其他地方找到有关此信息。

正确的方法是:

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM