function _ctools_plugin_configure_create_form_info

1 call to _ctools_plugin_configure_create_form_info()
ctools_plugin_configure_form in includes/plugins-admin.inc
Get a plugin configuration form.

File

includes/plugins-admin.inc, line 68

Code

function _ctools_plugin_configure_create_form_info(&$form_info, $plugin_definition, $op) {
    // Provide a few extra defaults.
    $form_info += array(
        'id' => 'ctools_plugin_configure_form',
        'show back' => TRUE,
    );
    $add_form = isset($form_info['add form name']) ? $form_info['add form name'] : 'add form';
    $edit_form = isset($form_info['edit form name']) ? $form_info['edit form name'] : 'edit form';
    // Figure out what the forms should actually be. Since they can be specified
    // in a couple of different ways (in order to support simple declarations for
    // the minimal forms but more complex declarations for powerful wizards).
    if ($op == 'add') {
        if (!empty($plugin_definition[$add_form])) {
            $info = $plugin_definition[$add_form];
        }
    }
    if (!isset($info) || $op == 'edit') {
        // Use the edit form for the add form if add form was completely left off.
        if (!empty($plugin_definition[$edit_form])) {
            $info = $plugin_definition[$edit_form];
        }
    }
    // If there is a default form wrapper, but no form is supplied,
    // use the wrapper as the form.
    if (empty($info) && !empty($form_info['default form'])) {
        $info = $form_info['default form'];
    }
    // @todo we may want to make these titles more settable?
    if (is_string($info)) {
        if (empty($plugin_definition['title'])) {
            $title = t('Configure');
        }
        elseif ($op == 'add') {
            $title = t('Configure new !plugin_title', array(
                '!plugin_title' => $plugin_definition['title'],
            ));
        }
        else {
            $title = t('Configure !plugin_title', array(
                '!plugin_title' => $plugin_definition['title'],
            ));
        }
        if (empty($form_info['order'])) {
            $form_info['order'] = array();
        }
        $form_info['order']['form'] = $title;
        if (empty($form_info['forms'])) {
            $form_info['forms'] = array();
        }
        $form_info['forms']['form'] = array(
            'title' => $title,
            'form id' => $info,
        );
        // Add the default form if one is specified.
        if (!empty($form_info['default form']) && $form_info['forms']['form']['form id'] != $form_info['default form']) {
            $form_info['forms']['form']['wrapper'] = $form_info['default form'];
        }
        // If no submit is supplied, supply the default submit which will do the
        // most obvious task.
        if (!function_exists($form_info['forms']['form']['form id'] . '_submit')) {
            // Store the original wrapper so we can chain it.
            if (!empty($form_info['forms']['form']['wrapper'])) {
                $form_info['forms']['form']['original wrapper'] = $form_info['forms']['form']['wrapper'];
            }
            $form_info['forms']['form']['wrapper'] = 'ctools_plugins_default_form_wrapper';
        }
    }
    elseif (is_array($info)) {
        if (empty($form_info['order'])) {
            $form_info['order'] = array();
        }
        if (empty($form_info['forms'])) {
            $form_info['forms'] = array();
        }
        $count = 0;
        $base = 'step';
        $wrapper = NULL;
        foreach ($info as $form_id => $title) {
            $step = $base . ++$count;
            if (empty($wrapper)) {
                $wrapper = $step;
            }
            if (is_array($title)) {
                if (!empty($title['default'])) {
                    $wrapper = $step;
                }
                $title = $title['title'];
            }
            $form_info['order'][$step] = $title;
            $form_info['forms'][$step] = array(
                'title' => $title,
                'form id' => $form_id,
            );
        }
        if ($wrapper && !empty($form_info['default form'])) {
            $form_info['forms'][$wrapper]['wrapper'] = $form_info['default form'];
        }
    }
}