function page_manager_page_subtask_argument_ajax

Ajax entry point to edit an item.

1 string reference to 'page_manager_page_subtask_argument_ajax'
page_manager_page_menu in page_manager/plugins/tasks/page.admin.inc
Delegated implementation of hook_menu().

File

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

Code

function page_manager_page_subtask_argument_ajax($step = NULL, $task_name = NULL, $keyword = NULL) {
    ctools_include('ajax');
    ctools_include('modal');
    ctools_include('context');
    ctools_include('wizard');
    if (!$step) {
        return ctools_ajax_render_error();
    }
    if (!($cache = page_manager_get_page_cache($task_name))) {
        return ctools_ajax_render_error(t('Invalid object name.'));
    }
    $page =& $cache->subtask['subtask'];
    $path = $page->path;
    $arguments = page_manager_page_get_named_arguments($path);
    // Load stored object from cache.
    if (!isset($arguments[$keyword])) {
        return ctools_ajax_render_error(t('Invalid keyword.'));
    }
    // Set up wizard info.
    $form_info = array(
        'id' => 'page_manager_page_argument',
        'path' => "admin/structure/pages/argument/%step/{$task_name}/{$keyword}",
        'show cancel' => TRUE,
        'next callback' => 'page_manager_page_argument_next',
        'finish callback' => 'page_manager_page_argument_finish',
        'cancel callback' => 'page_manager_page_argument_cancel',
        'order' => array(
            'change' => t('Change context type'),
            'settings' => t('Argument settings'),
        ),
        'forms' => array(
            'change' => array(
                'title' => t('Change argument'),
                'form id' => 'page_manager_page_argument_form_change',
            ),
            'settings' => array(
                'title' => t('Argument settings'),
                'form id' => 'page_manager_page_argument_form_settings',
            ),
        ),
    );
    $form_state = array(
        'page' => $cache,
        'keyword' => $keyword,
        'ajax' => TRUE,
        'modal' => TRUE,
        'modal return' => TRUE,
        'commands' => array(),
    );
    $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
    if (!empty($form_state['cancel'])) {
        $commands = array(
            ctools_modal_command_dismiss(),
        );
    }
    elseif (!empty($form_state['complete'])) {
        if (isset($page->temporary_arguments[$keyword])) {
            $page->arguments[$keyword] = $page->temporary_arguments[$keyword];
        }
        if (isset($page->temporary_arguments)) {
            unset($page->temporary_arguments);
        }
        // Update the cache with changes.
        page_manager_set_page_cache($cache);
        // Rerender the table so we can ajax it back in.
        // Go directly to the form and retrieve it using a blank form and
        // a clone of our current form state. This is an abbreviated
        // drupal_get_form that is halted prior to render and is never
        // fully processed, but is guaranteed to produce the same form we
        // started with so we don't have to do crazy stuff to rerender
        // just part of it.
        // @todo should there be a tool to do this?
        $clone_state = $form_state;
        $clone_state['allow temp'] = TRUE;
        $form = drupal_build_form('page_manager_page_form_argument', $form_state);
        // Render just the table portion.
        $output = drupal_render($form['table']);
        $commands = array(
            ajax_command_replace('#page-manager-argument-table', $output),
            ctools_modal_command_dismiss(),
        );
    }
    else {
        $commands = ctools_modal_form_render($form_state, $output);
    }
    print ajax_render($commands);
    ajax_footer();
    exit;
}