function views_ui_standard_form_buttons

Provide a standard set of Apply/Cancel/OK buttons for the forms. Also provide a hidden op operator because the forms plugin doesn't seem to properly provide which button was clicked.

@todo Is the hidden op operator still here somewhere, or is that part of the docblock outdated?

12 calls to views_ui_standard_form_buttons()
views_ui_add_item_form in includes/admin.inc
Form to add_item items in the views UI.
views_ui_analyze_view_form in includes/admin.inc
Form constructor callback to display analysis information on a view.
views_ui_config_item_extra_form in includes/admin.inc
Form to config_item items in the views UI.
views_ui_config_item_form in includes/admin.inc
Form to config_item items in the views UI.
views_ui_config_item_group_form in includes/admin.inc
Form to config_item items in the views UI.

... See full list

File

includes/admin.inc, line 2592

Code

function views_ui_standard_form_buttons(&$form, &$form_state, $form_id, $name = NULL, $third = NULL, $submit = NULL) {
    $form['buttons'] = array(
        '#prefix' => '<div class="clearfix"><div class="form-buttons">',
        '#suffix' => '</div></div>',
    );
    if (empty($name)) {
        $name = t('Apply');
        $view = $form_state['view'];
        if (!empty($view->stack) && count($view->stack) > 1) {
            $name = t('Apply and continue');
        }
        $names = array(
            t('Apply'),
            t('Apply and continue'),
        );
    }
    // Forms that are purely informational set an ok_button flag, so we know not
    // to create an "Apply" button for them.
    if (empty($form_state['ok_button'])) {
        $form['buttons']['submit'] = array(
            '#type' => 'submit',
            '#value' => $name,
            // The regular submit handler ($form_id . '_submit') does not apply if
            // we're updating the default display. It does apply if we're updating
            // the current display. Since we have no way of knowing at this point
            // which display the user wants to update, views_ui_standard_submit will
            // take care of running the regular submit handler as appropriate.
'#submit' => array(
                'views_ui_standard_submit',
            ),
        );
        // Form API button click detection requires the button's #value to be the
        // same between the form build of the initial page request, and the initial
        // form build of the request processing the form submission. Ideally, the
        // button's #value shouldn't change until the form rebuild step. However,
        // views_ui_ajax_form() implements a different multistep form workflow than
        // the Form API does, and adjusts $view->stack prior to form processing, so
        // we compensate by extending button click detection code to support any of
        // the possible button labels.
        if (isset($names)) {
            $form['buttons']['submit']['#values'] = $names;
            $form['buttons']['submit']['#process'] = array_merge(array(
                'views_ui_form_button_was_clicked',
            ), element_info_property($form['buttons']['submit']['#type'], '#process', array()));
        }
        // If a validation handler exists for the form, assign it to this button.
        if (function_exists($form_id . '_validate')) {
            $form['buttons']['submit']['#validate'][] = $form_id . '_validate';
        }
    }
    // Create a "Cancel" button. For purely informational forms, label it "OK".
    $cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : 'views_ui_standard_cancel';
    $form['buttons']['cancel'] = array(
        '#type' => 'submit',
        '#value' => empty($form_state['ok_button']) ? t('Cancel') : t('Ok'),
        '#submit' => array(
            $cancel_submit,
        ),
        '#validate' => array(),
    );
    // Some forms specify a third button, with a name and submit handler.
    if ($third) {
        if (empty($submit)) {
            $submit = 'third';
        }
        $third_submit = function_exists($form_id . '_' . $submit) ? $form_id . '_' . $submit : 'views_ui_standard_cancel';
        $form['buttons'][$submit] = array(
            '#type' => 'submit',
            '#value' => $third,
            '#validate' => array(),
            '#submit' => array(
                $third_submit,
            ),
        );
    }
    // Compatibility, to be removed later: // @todo When is "later"? We used to
    // set these items on the form, but now we want them on the $form_state.
    if (isset($form['#title'])) {
        $form_state['title'] = $form['#title'];
    }
    if (isset($form['#help_topic'])) {
        $form_state['help_topic'] = $form['#help_topic'];
    }
    if (isset($form['#help_module'])) {
        $form_state['help_module'] = $form['#help_module'];
    }
    if (isset($form['#url'])) {
        $form_state['url'] = $form['#url'];
    }
    if (isset($form['#section'])) {
        $form_state['#section'] = $form['#section'];
    }
    // Finally, we never want these cached -- our object cache does that for us.
    $form['#no_cache'] = TRUE;
    // If this isn't an ajaxy form, then we want to set the title.
    if (!empty($form['#title'])) {
        drupal_set_title($form['#title']);
    }
}