简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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