_batch_progress_page()
Outputs a batch processing page.
See also
File
- core/includes/batch.inc, line 105
- Batch processing API for processes to run in multiple HTTP requests.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | function _batch_progress_page() { $batch = &batch_get(); $current_set = _batch_current_set(); $new_op = 'do_nojs' ; if (!isset( $batch [ 'running' ])) { // This is the first page so we return some output immediately. $percentage = 0; $message = $current_set [ 'init_message' ]; $label = '' ; $batch [ 'running' ] = TRUE; } else { // This is one of the later requests; do some processing first. // Error handling: if PHP dies due to a fatal error (e.g. a nonexistent // function), it will output whatever is in the output buffer, followed by // the error message. ob_start(); $fallback = $current_set [ 'error_message' ] . '<br />' . $batch [ 'error_message' ]; // We strip the end of the page using a marker in the template, so any // additional HTML output by PHP shows up inside the page rather than below // it. While this causes invalid HTML, the same would be true if we didn't, // as content is not allowed to appear after </html> anyway. $bare_html_page_renderer = \Drupal::service( 'bare_html_page_renderer' ); $response = $bare_html_page_renderer ->renderBarePage([ '#markup' => $fallback ], $current_set [ 'title' ], 'maintenance_page' , array ( '#show_messages' => FALSE, )); // Just use the content of the response. $fallback = $response ->getContent(); list( $fallback ) = explode ( '<!--partial-->' , $fallback ); print $fallback ; // Perform actual processing. list( $percentage , $message , $label ) = _batch_process( $batch ); if ( $percentage == 100) { $new_op = 'finished' ; } // PHP did not die; remove the fallback output. ob_end_clean(); } // Merge required query parameters for batch processing into those provided by // batch_set() or hook_batch_alter(). $query_options = $batch [ 'url' ]->getOption( 'query' ); $query_options [ 'id' ] = $batch [ 'id' ]; $query_options [ 'op' ] = $new_op ; $batch [ 'url' ]->setOption( 'query' , $query_options ); $url = $batch [ 'url' ]->toString(TRUE)->getGeneratedUrl(); $build = array ( '#theme' => 'progress_bar' , '#percent' => $percentage , '#message' => array ( '#markup' => $message ), '#label' => $label , '#attached' => array ( 'html_head' => array ( array ( array ( // Redirect through a 'Refresh' meta tag if JavaScript is disabled. '#tag' => 'meta' , '#noscript' => TRUE, '#attributes' => array ( 'http-equiv' => 'Refresh' , 'content' => '0; URL=' . $url , ), ), 'batch_progress_meta_refresh' , ), ), // Adds JavaScript code and settings for clients where JavaScript is enabled. 'drupalSettings' => [ 'batch' => [ 'errorMessage' => $current_set [ 'error_message' ] . '<br />' . $batch [ 'error_message' ], 'initMessage' => $current_set [ 'init_message' ], 'uri' => $url , ], ], 'library' => array ( 'core/drupal.batch' , ), ), ); return $build ; } |
Please login to continue.