public function TMGMTEntitySourceUIController::overviewFormSubmit in Translation Management Tool 7
Overrides TMGMTDefaultSourceUIController::overviewFormSubmit
File
- sources/
entity/ ui/ tmgmt_entity_ui.ui.inc, line 120
Class
- TMGMTEntitySourceUIController
- Generic entity ui controller class for source plugin.
Code
public function overviewFormSubmit($form, &$form_state, $type) {
// Handle search redirect.
$this
->overviewSearchFormRedirect($form, $form_state, $type);
$jobs = array();
$entities = entity_load($type, $form_state['values']['items']);
$source_lang_registry = array();
// Loop through entities and create individual jobs for each source language.
foreach ($entities as $entity) {
/**
* @var EntityTranslationDefaultHandler $handler
*/
$handler = entity_translation_get_handler($type, $entity);
$source_lang = entity_language($type, $entity);
list($entity_id, , ) = entity_extract_ids($type, $entity);
try {
// For given source lang no job exists yet.
if (!isset($source_lang_registry[$source_lang])) {
// Create new job.
$job = tmgmt_job_create($source_lang, NULL, $GLOBALS['user']->uid);
// Add initial job item.
$job
->addItem('entity', $type, $entity_id);
// Add job identifier into registry
$source_lang_registry[$source_lang] = $job->tjid;
// Add newly created job into jobs queue.
$jobs[$job->tjid] = $job;
}
else {
$jobs[$source_lang_registry[$source_lang]]
->addItem('entity', $type, $entity_id);
}
} catch (TMGMTException $e) {
watchdog_exception('tmgmt', $e);
$entity_label = entity_label($type, $entity);
drupal_set_message(t('Unable to add job item for entity %name: %error.', array(
'%name' => $entity_label,
'%error' => $e
->getMessage(),
)), 'error');
}
}
// If necessary, do a redirect.
$redirects = tmgmt_ui_job_checkout_multiple($jobs);
if ($redirects) {
tmgmt_ui_redirect_queue_set($redirects, current_path());
$form_state['redirect'] = tmgmt_ui_redirect_queue_dequeue();
drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.')));
}
}