function ctools_stylizer_edit_style

Add a new style of the specified type.

File

includes/stylizer.inc, line 673

Code

function ctools_stylizer_edit_style(&$info, $js, $step = NULL) {
    $name = '::new';
    $form_info = array(
        'id' => 'ctools_stylizer_edit_style',
        'path' => $info['path'],
        'show trail' => TRUE,
        'show back' => TRUE,
        'show return' => FALSE,
        'next callback' => 'ctools_stylizer_edit_style_next',
        'finish callback' => 'ctools_stylizer_edit_style_finish',
        'return callback' => 'ctools_stylizer_edit_style_finish',
        'cancel callback' => 'ctools_stylizer_edit_style_cancel',
        'forms' => array(
            'choose' => array(
                'form id' => 'ctools_stylizer_edit_style_form_choose',
            ),
        ),
    );
    if (empty($info['settings'])) {
        $form_info['order'] = array(
            'choose' => t('Select base style'),
        );
        if (empty($step)) {
            $step = 'choose';
        }
        if ($step != 'choose') {
            $cache = ctools_stylizer_get_settings_cache($name);
            if (!$cache) {
                $output = t('Missing settings cache.');
                if ($js) {
                    return ctools_modal_form_render($form_state, $output);
                }
                else {
                    return $output;
                }
            }
            if (!empty($cache['owner settings'])) {
                $info['owner settings'] = $cache['owner settings'];
            }
            $settings = $cache['settings'];
        }
        else {
            $settings = array(
                'name' => '_temporary',
                'style_base' => NULL,
                'palette' => array(),
            );
            ctools_stylizer_clear_settings_cache($name);
        }
        $op = 'add';
    }
    else {
        $cache = ctools_stylizer_get_settings_cache($info['settings']['name']);
        if (!empty($cache)) {
            if (!empty($cache['owner settings'])) {
                $info['owner settings'] = $cache['owner settings'];
            }
            $settings = $cache['settings'];
        }
        else {
            $settings = $info['settings'];
        }
        $op = 'edit';
    }
    if (!empty($info['op'])) {
        // Allow this to override. Necessary to allow cloning properly.
        $op = $info['op'];
    }
    $plugin = NULL;
    if (!empty($settings['style_base'])) {
        $plugin = ctools_get_style_base($settings['style_base']);
        $info['type'] = $plugin['type'];
        ctools_stylizer_add_plugin_forms($form_info, $plugin, $op);
    }
    else {
        // This is here so the 'finish' button does not show up, and because
        // we don't have the selected style we don't know what the next form(s)
        // will be.
        $form_info['order']['next'] = t('Configure style');
    }
    if (count($form_info['order']) < 2 || $step == 'choose') {
        $form_info['show trail'] = FALSE;
    }
    $form_state = array(
        'module' => $info['module'],
        'type' => $info['type'],
        'owner info' => &$info,
        'base_style_plugin' => $plugin,
        'name' => $name,
        'step' => $step,
        'settings' => $settings,
        'ajax' => $js,
        'op' => $op,
    );
    if (!empty($info['modal'])) {
        $form_state['modal'] = TRUE;
        $form_state['title'] = $info['modal'];
        $form_state['modal return'] = TRUE;
    }
    ctools_include('wizard');
    $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
    if (!empty($form_state['complete'])) {
        $info['complete'] = TRUE;
        $info['settings'] = $form_state['settings'];
    }
    if ($js && !$output && !empty($form_state['clicked_button']['#next'])) {
        // We have to do a separate redirect here because the formula that adds
        // stuff to the wizard after being chosen hasn't happened. The wizard
        // tried to go to the next step which did not exist.
        return ctools_stylizer_edit_style($info, $js, $form_state['clicked_button']['#next']);
    }
    if ($js) {
        return ctools_modal_form_render($form_state, $output);
    }
    else {
        return $output;
    }
}