You are here

function tmgmt_node_ui_checkout_multiple_action in Translation Management Tool 7

Action to do multistep checkout for translations.

Parameters

array $nodes: Array of Drupal nodes.

$info: Action info - not used.

File

sources/node/ui/tmgmt_node_ui.module, line 52
Main module file for the translation management node source plugin user interface.

Code

function tmgmt_node_ui_checkout_multiple_action($nodes, $info) {
  $jobs = array();
  $source_lang_registry = array();

  // Loop through entities and create individual jobs for each source language.
  foreach ($nodes as $node) {
    try {

      // For given source lang no job exists yet.
      if (!isset($source_lang_registry[$node->language])) {

        // Create new job.
        $job = tmgmt_job_create($node->language, NULL, $GLOBALS['user']->uid);

        // Add initial job item.
        $job
          ->addItem('node', 'node', $node->nid);

        // Add job identifier into registry
        $source_lang_registry[$node->language] = $job->tjid;

        // Add newly created job into jobs queue.
        $jobs[$job->tjid] = $job;
      }
      else {
        $jobs[$source_lang_registry[$node->language]]
          ->addItem('node', 'node', $node->nid);
      }
    } catch (TMGMTException $e) {
      watchdog_exception('tmgmt', $e);
      drupal_set_message(t('Unable to add job item for node %name. Make sure the source content is not empty.', array(
        '%name' => $node->title,
      )), 'error');
    }
  }

  // If necessary, do a redirect.
  $redirects = tmgmt_ui_job_checkout_multiple($jobs);
  if ($redirects) {
    tmgmt_ui_redirect_queue_set($redirects, current_path());
    drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.')));
    drupal_goto(tmgmt_ui_redirect_queue_dequeue());
  }
}