function page_manager_page_argument_form_change_submit

Submit handler to change an argument.

File

page_manager/plugins/tasks/page.admin.inc, line 1143

Code

function page_manager_page_argument_form_change_submit(&$form, &$form_state) {
    $page =& $form_state['page']->subtask['subtask'];
    $keyword =& $form_state['keyword'];
    $argument = $form_state['values']['argument'];
    // If the argument is not changing, we do not need to do anything.
    if (isset($page->arguments[$keyword]['name']) && $page->arguments[$keyword]['name'] == $argument) {
        // Set the task to cancel since no change means do nothing:
        $form_state['clicked_button']['#wizard type'] = 'cancel';
        return;
    }
    ctools_include('context');
    // If switching to the no context, just wipe out the old data.
    if (empty($argument)) {
        $form_state['clicked_button']['#wizard type'] = 'finish';
        $page->temporary_arguments[$keyword] = array(
            'settings' => array(),
            'identifier' => t('No context'),
        );
        return;
    }
    $plugin = ctools_get_argument($argument);
    // Acquire defaults.
    $settings = array();
    if (isset($plugin['default'])) {
        if (is_array($plugin['default'])) {
            $settings = $plugin['default'];
        }
        elseif (function_exists($plugin['default'])) {
            $settings = $plugin['default']();
        }
    }
    $id = ctools_context_next_id($page->arguments, $argument);
    $title = isset($plugin['title']) ? $plugin['title'] : t('No context');
    // Set the new argument in a temporary location.
    $page->temporary_arguments[$keyword] = array(
        'id' => $id,
        'identifier' => $title . ($id > 1 ? ' ' . $id : ''),
        'name' => $argument,
        'settings' => $settings,
    );
}