function shortcut_set_switch_submit

Submit handler for shortcut_set_switch().

File

modules/shortcut/shortcut.admin.inc, line 125

Code

function shortcut_set_switch_submit($form, &$form_state) {
    global $user;
    $account = $form_state['values']['account'];
    if ($form_state['values']['set'] == 'new') {
        // Save a new shortcut set with links copied from the user's default set.
        $default_set = shortcut_default_set($account);
        $set = (object) array(
            'title' => $form_state['values']['new'],
            'links' => menu_links_clone($default_set->links),
        );
        shortcut_set_save($set);
        $replacements = array(
            '%user' => $account->name,
            '%set_name' => $set->title,
            '@switch-url' => url(current_path()),
        );
        if ($account->uid == $user->uid) {
            // Only administrators can create new shortcut sets, so we know they have
            // access to switch back.
            drupal_set_message(t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
        }
        else {
            drupal_set_message(t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
        }
        $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $set->set_name;
    }
    else {
        // Switch to a different shortcut set.
        $set = shortcut_set_load($form_state['values']['set']);
        $replacements = array(
            '%user' => $account->name,
            '%set_name' => $set->title,
        );
        drupal_set_message($account->uid == $user->uid ? t('You are now using the %set_name shortcut set.', $replacements) : t('%user is now using the %set_name shortcut set.', $replacements));
    }
    // Assign the shortcut set to the provided user account.
    shortcut_set_assign_user($set, $account);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.