You are here

function uc_cart_links_form in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_cart_links/uc_cart_links.pages.inc \uc_cart_links_form()

Preprocesses a Cart Link, confirming with the user for destructive actions.

Parameters

string $cart_actions: A Cart Link URL is structured like "/cart/add/$cart_actions".

See also

uc_cart_links_form_submit()

1 string reference to 'uc_cart_links_form'
uc_cart_links_menu in uc_cart_links/uc_cart_links.module
Implements hook_menu().

File

uc_cart_links/uc_cart_links.pages.inc, line 16
Cart Links menu items.

Code

function uc_cart_links_form($form, &$form_state, $cart_actions) {

  // Fail if the link is restricted.
  $data = variable_get('uc_cart_links_restrictions', '');
  if (!empty($data)) {
    $restrictions = explode("\n", variable_get('uc_cart_links_restrictions', ''));
    $restrictions = array_map('trim', $restrictions);
    if (!empty($restrictions) && !in_array($cart_actions, $restrictions)) {
      $url = variable_get('uc_cart_links_invalid_page', '');
      if (empty($url)) {
        $url = '<front>';
      }
      unset($_GET['destination']);
      drupal_goto($url);
    }
  }

  // Confirm with the user if the form contains a destructive action.
  $items = uc_cart_get_contents();
  if (variable_get('uc_cart_links_empty', TRUE) && !empty($items)) {
    $actions = explode('-', urldecode($cart_actions));
    foreach ($actions as $action) {
      $action = drupal_substr($action, 0, 1);
      if ($action == 'e' || $action == 'E') {
        return confirm_form(array(), t('The current contents of your shopping cart will be lost. Are you sure you want to continue?'), variable_get('uc_cart_links_invalid_page', ''));
      }
    }
  }

  // No destructive actions, so process the link immediately.
  uc_cart_links_process($cart_actions);
}