You are here

function tmgmt_ui_source_add_to_cart_submit in Translation Management Tool 7

Submit handler to add items into the cart.

Based on the submitted data it will create job items and add them into the cart. Use it in combination with tmgmt_ui_add_cart_form() as that function sets all the necessary values needed to crate a job an add it into the cart.

See also

tmgmt_ui_add_cart_form()

Related topics

1 string reference to 'tmgmt_ui_source_add_to_cart_submit'
tmgmt_ui_add_cart_form in ui/tmgmt_ui.module
Adds add to cart form elements.

File

ui/tmgmt_ui.module, line 378
Common Translation managment UI.

Code

function tmgmt_ui_source_add_to_cart_submit($form, &$form_state) {
  $cart_info = $form_state['tmgmt_cart'];
  if (!empty($cart_info['plugin']) && !empty($cart_info['item_type']) && !empty($form_state['values']['items'])) {
    $source_items = array_filter($form_state['values']['items']);
    $item_type = $cart_info['item_type'];
    $plugin = $cart_info['plugin'];
  }
  elseif (!empty($cart_info['plugin']) && !empty($cart_info['item_type']) && !empty($cart_info['item_id'])) {
    $source_items = array(
      $cart_info['item_id'],
    );
    $item_type = $cart_info['item_type'];
    $plugin = $cart_info['plugin'];
  }
  else {
    drupal_set_message(t('Unable to add the content into the cart.'), 'error');
    return;
  }
  $i = 0;
  foreach ($source_items as $source_id) {
    if (tmgmt_ui_cart_get()
      ->addJobItem($plugin, $item_type, $source_id)) {
      $i++;
    }
  }
  drupal_set_message(format_plural($i, '@count content source was added into the <a href="@url">cart</a>.', '@count content sources were added into the <a href="@url">cart</a>.', array(
    '@url' => url('admin/tmgmt/cart'),
  )));
}