You are here

function commerce_checkout_builder_form in Commerce Core 7

Build the checkout form builder, adding in data for the checkout pages and the appropriate fields to enable tabledrag on the checkout panes.

1 string reference to 'commerce_checkout_builder_form'
commerce_checkout_menu in modules/checkout/commerce_checkout.module
Implements hook_menu().

File

modules/checkout/includes/commerce_checkout.admin.inc, line 13
Administrative callbacks for the Checkout module.

Code

function commerce_checkout_builder_form($form, &$form_state) {

  // Load an array of all available checkout pages.
  $checkout_pages = commerce_checkout_pages();

  // Add a "disabled" pseudo-page.
  $checkout_pages['disabled'] = array(
    'page_id' => 'disabled',
    'name' => t('Disabled'),
  );
  $form['checkout_pages'] = array(
    '#type' => 'value',
    '#value' => $checkout_pages,
  );
  $checkout_pages_options = array();

  // Create arrays for checkout panes in each of the pages.
  foreach (array_keys($checkout_pages) as $page_id) {
    $form['page'][$page_id]['panes'] = array(
      '#tree' => TRUE,
    );

    // Build the options list for selecting the pane's checkout page.
    $checkout_pages_options[$page_id] = $checkout_pages[$page_id]['name'];
  }

  // Loop through all the checkout panes on the site.
  $panes = commerce_checkout_panes();
  foreach ($panes as $pane_id => $checkout_pane) {

    // Determine a checkout pane's current checkout page.
    $page_id = $checkout_pane['enabled'] ? $checkout_pane['page'] : 'disabled';

    // If the page no longer exists, place the pane on the first page.
    if (empty($checkout_pages[$page_id])) {
      reset($checkout_pages);
      $page_id = key($checkout_pages);
    }

    // Add the pane's name to the form array.
    $form['page'][$page_id]['panes'][$pane_id]['name'] = array(
      '#markup' => check_plain($checkout_pane['name']),
    );

    // Add the select field for the pane's checkout page.
    $form['page'][$page_id]['panes'][$pane_id]['page'] = array(
      '#type' => 'select',
      '#options' => $checkout_pages_options,
      '#default_value' => $checkout_pane['page'],
      '#attributes' => array(
        'class' => array(
          'checkout-pane-page checkout-pane-page-' . $checkout_pane['page'],
        ),
      ),
    );

    // Add the select field for the pane's weight.
    $form['page'][$page_id]['panes'][$pane_id]['weight'] = array(
      '#type' => 'weight',
      '#delta' => 20,
      '#default_value' => $checkout_pane['weight'],
      '#attributes' => array(
        'class' => array(
          'checkout-pane-weight checkout-pane-weight-' . $checkout_pane['page'],
        ),
      ),
    );

    // Add a configuration link for the pane.
    $form['page'][$page_id]['panes'][$pane_id]['ops'] = array(
      '#markup' => l(t('configure'), 'admin/commerce/config/checkout/form/pane/' . $pane_id),
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
    '#tree' => FALSE,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
    '#submit' => array(
      'commerce_checkout_builder_form_save_submit',
    ),
  );
  $form['actions']['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
    '#submit' => array(
      'commerce_checkout_builder_form_reset_submit',
    ),
  );
  return $form;
}