You are here

function theme_commerce_checkout_builder_form in Commerce Core 7

Theme the checkout pages form to enable tabledrag.

File

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

Code

function theme_commerce_checkout_builder_form($variables) {
  $form = $variables['form'];
  drupal_add_css(drupal_get_path('module', 'commerce_checkout') . '/theme/commerce_checkout.admin.css');
  drupal_add_js(drupal_get_path('module', 'commerce_checkout') . '/commerce_checkout_admin.js');

  // Build the full table header; Page and Weight will be hidden by tabledrag.
  $header = array(
    t('Checkout pane'),
    t('Page'),
    t('Weight'),
    t('Operations'),
  );
  $rows = array();

  // Loop through each page array in the form.
  foreach ($form['checkout_pages']['#value'] as $page_id => $checkout_page) {

    // Initialize the tabledrag for this page.
    drupal_add_tabledrag('panes', 'match', 'sibling', 'checkout-pane-page', 'checkout-pane-page-' . $page_id);
    drupal_add_tabledrag('panes', 'order', 'sibling', 'checkout-pane-weight', 'checkout-pane-weight-' . $page_id);

    // Add a non-draggable header row for each checkout page.
    $row = array(
      array(
        'data' => $checkout_page['name'],
        'colspan' => 4,
      ),
    );
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'page-header',
      ),
    );

    // Determine whether the page currently has any panes in it.
    $class = count(element_children($form['page'][$page_id]['panes'])) == 0 ? 'page-empty' : 'page-populated';

    // Add a row to the table that will be automatically shown or hidden as a
    // placeholder for pages that do not have any panes.
    $rows[] = array(
      'data' => array(
        array(
          'data' => $page_id != 'disabled' ? t('No panes on this page.') : t('No disabled panes.'),
          'colspan' => 4,
        ),
      ),
      'class' => array(
        'page-message page-' . $page_id . '-message',
        $class,
      ),
    );

    // Loop through each checkout pane currently assigned to this page.
    foreach (element_children($form['page'][$page_id]['panes']) as $pane_id) {
      $row = array(
        drupal_render($form['page'][$page_id]['panes'][$pane_id]['name']),
        drupal_render($form['page'][$page_id]['panes'][$pane_id]['page']),
        drupal_render($form['page'][$page_id]['panes'][$pane_id]['weight']),
        drupal_render($form['page'][$page_id]['panes'][$pane_id]['ops']),
      );
      $rows[] = array(
        'data' => $row,
        'class' => array(
          'draggable',
        ),
      );
    }
  }
  $variables = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'panes',
    ),
  );
  return theme('table', $variables) . drupal_render_children($form);
}