function tmgmt_ui_add_cart_form in Translation Management Tool 7
Adds add to cart form elements.
There are two use cases for this function:
1) Add the "Add to cart" submit action to the source overview form. In this case the $item_id should not be provided and only the action button will be displayed. The form is expected to submit job items ids as items[] which is being validated via tmgmt_ui_source_add_to_cart_validate().
2) Add the "Add to cart" submit action to the translate tab. For this case the $item_id is required and with the add to cart button also the cart information is displayed. In this case there is no validation as the caller needs to provide valid $item_id value.
The "Add to cart" action submits the form by calling tmgmt_ui_source_add_to_cart_submit() submit callback which processes either one job item or multiple.
Parameters
array $form: Form to which to add the add to cart form elements.
array $form_state: The current form state object.
string $plugin: Current plugin name.
string $item_type: Type of the source item.
mixed $item_id: (Optional) It is required in case a single source is being added into the cart.
Related topics
4 calls to tmgmt_ui_add_cart_form()
- tmgmt_entity_ui_translate_form in sources/
entity/ ui/ tmgmt_entity_ui.pages.inc - Entity translation overview form.
- tmgmt_i18n_string_form_i18n_string_translate_page_overview_form_alter in sources/
i18n_string/ tmgmt_i18n_string.module - Implements hook_form_ID_alter().
- tmgmt_node_ui_node_form in sources/
node/ ui/ tmgmt_node_ui.pages.inc - Node translation overview form. This form overrides the Drupal core or i18n Content Translation page with a tableselect form.
- tmgmt_ui_source_overview_form_defaults in ui/
tmgmt_ui.module - Form callback for the source overview form.
File
- ui/
tmgmt_ui.module, line 334 - Common Translation managment UI.
Code
function tmgmt_ui_add_cart_form(&$form, &$form_state, $plugin, $item_type, $item_id = NULL) {
$form_state['tmgmt_cart'] = array(
'plugin' => $plugin,
'item_type' => $item_type,
'item_id' => $item_id,
);
$form['add_to_cart'] = array(
'#type' => 'submit',
'#value' => t('Add to cart'),
'#submit' => array(
'tmgmt_ui_source_add_to_cart_submit',
),
'#attributes' => array(
'title' => t('Add marked items to the cart for later processing'),
),
);
if (empty($item_id)) {
$form['add_to_cart']['#validate'] = array(
'tmgmt_ui_cart_source_overview_validate',
);
}
else {
//
$form['add_to_cart']['#limit_validation_errors'] = array();
// Compose the cart info message for the translate tab.
$count = tmgmt_ui_cart_get()
->count();
if (tmgmt_ui_cart_get()
->isSourceItemAdded($plugin, $item_type, $item_id)) {
$form['add_to_cart']['#disabled'] = TRUE;
$message = format_plural($count, 'There is @count item in the <a href="@url">translation cart</a> including the current item.', 'There are @count items in the <a href="@url">translation cart</a> including the current item.', array(
'@url' => url('admin/tmgmt/cart'),
));
}
else {
$message = format_plural($count, 'There is @count item in the <a href="@url">translation cart</a>.', 'There are @count items in the <a href="@url">translation cart</a>.', array(
'@url' => url('admin/tmgmt/cart'),
));
}
$form['add_to_cart']['#suffix'] = '<span class="tmgmt-ui-cart-status-message">' . $message . '</span>';
}
}