function commerce_cp_builder_form in Commerce Cart Pane 7
Build the cart form builder, adding in data for the cart pages and the appropriate fields to enable tabledrag on the cart panes.
1 string reference to 'commerce_cp_builder_form'
- commerce_cp_menu in ./
commerce_cp.module - Implements hook_menu().
File
- ./
commerce_cp.admin.inc, line 30 - Administrative callbacks for the Checkout module.
Code
function commerce_cp_builder_form($form, &$form_state) {
// Load an array of all available cart pages.
$cart_pages['cart'] = array(
'page_id' => 'cart',
'title' => t('Cart'),
);
// Add a "disabled" pseudo-page.
$cart_pages['disabled'] = array(
'page_id' => 'disabled',
'title' => t('Disabled'),
);
$form['cart_pages'] = array(
'#type' => 'value',
'#value' => $cart_pages,
);
$cart_pages_options = array();
// Create arrays for cart panes in each of the pages.
foreach (array_keys($cart_pages) as $page_id) {
$form['page'][$page_id]['panes'] = array(
'#tree' => TRUE,
);
// Build the options list for selecting the pane's cart page.
$cart_pages_options[$page_id] = $cart_pages[$page_id]['title'];
}
$cart_panes_weight = variable_get('commerce_cp_panes_weight', array());
$weight = 10;
// setup page and weight attributes for custom panes
$panes = module_invoke_all('commerce_cp_info');
foreach ($panes as $pane_id => $pane) {
$panes[$pane_id]['page'] = isset($cart_panes_weight[$pane_id]) ? 'cart' : 'disabled';
$panes[$pane_id]['weight'] = isset($cart_panes_weight[$pane_id]) ? $cart_panes_weight[$pane_id] : $weight;
$weight++;
}
uasort($panes, 'drupal_sort_weight');
foreach ($panes as $pane_id => $cart_pane) {
// Determine a cart pane's current cart page.
$page_id = $cart_pane['page'];
// If the page no longer exists, place the pane on the first page.
if (empty($cart_pages[$page_id])) {
reset($cart_pages);
$page_id = key($cart_pages);
}
$pane_name = check_plain($cart_pane['name']);
if (isset($cart_pane['warning message']) && !empty($cart_pane['warning message'])) {
$pane_name .= ' <small>' . $cart_pane['warning message'] . '</small>';
}
// Add the pane's name to the form array.
$form['page'][$page_id]['panes'][$pane_id]['name'] = array(
'#markup' => $pane_name,
);
// Add the select field for the pane's cart page.
$form['page'][$page_id]['panes'][$pane_id]['page'] = array(
'#type' => 'select',
'#options' => $cart_pages_options,
'#default_value' => $cart_pane['page'],
'#attributes' => array(
'class' => array(
'cart-pane-page cart-pane-page-' . $cart_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' => $cart_pane['weight'],
'#attributes' => array(
'class' => array(
'cart-pane-weight cart-pane-weight-' . $cart_pane['page'],
),
),
);
// , array('query' => drupal_get_destination())
if (isset($panes[$pane_id]['settings form'])) {
$settings_form_path = variable_get('commerce_cp_settings_form_path', 'admin/commerce/config/cart/form/pane');
// Add a configuration link for the pane.
$form['page'][$page_id]['panes'][$pane_id]['ops'] = array(
'#markup' => l(t('configure'), $settings_form_path . '/' . $pane_id, array(
'query' => drupal_get_destination(),
)),
);
}
}
$form['actions'] = array(
'#type' => 'actions',
'#tree' => FALSE,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
'#submit' => array(
'commerce_cp_builder_form_save_submit',
),
);
return $form;
}