You are here

function _taxonomy_menu_save_menu_links_process in Taxonomy menu 8

Same name and namespace in other branches
  1. 7.2 taxonomy_menu.batch.inc \_taxonomy_menu_save_menu_links_process()

Processes the batch.

Parameters

$terms: A list of taxonomy term objects to build the menu items upon.

$menu_name: The machine name of the menu in which the menu links should be inserted.

1 string reference to '_taxonomy_menu_save_menu_links_process'
_taxonomy_menu_save_menu_links_batch in ./taxonomy_menu.batch.inc
Saves link items in a menu based on available taxonomy terms.

File

./taxonomy_menu.batch.inc, line 39
Batch API Code.

Code

function _taxonomy_menu_save_menu_links_process($terms, $menu_name, &$context) {

  // Terms are processed 10 by 10.
  $limit = 10;

  // Initialize the sandbox the first time through.
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($terms);
  }

  // Store all the terms in the sandbox and retrieve the next
  // group of terms to be processed.
  $context['sandbox']['chunks'] = array_chunk($terms, $limit);

  // Loop through eack chunk and process its terms.
  foreach ($context['sandbox']['chunks'] as $chunk) {
    foreach ($chunk as $term) {

      // Save the menu link for this taxonomy term.
      taxonomy_menu_menu_link_save($term, $menu_name);

      // Store some result for post-processing in the finished callback.
      $context['results'][] = check_plain($term->name);

      // Update our progress information.
      $context['sandbox']['progress']++;
      $context['sandbox']['current_term'] = $term->tid;
    }

    // Inform the batch engine that we are not finished, and provide an estimation
    // of the completion level we reached.
    if ($context['sandbox']['progress'] < $context['sandbox']['max']) {
      $current_count = $context['sandbox']['max'] - $context['sandbox']['progress'];
      $context['message'] = t('Remaining %current taxonomy terms to process out of %count ...', array(
        '%current' => $current_count,
        '%count' => $context['sandbox']['max'],
      ));
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
    }
    else {
      $context['finished'] = 1;
    }
  }
}