Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / src / Controller / BatchController.php
1 <?php
2
3 namespace Drupal\system\Controller;
4
5 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpFoundation\Response;
9 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
10
11 /**
12  * Controller routines for batch routes.
13  */
14 class BatchController implements ContainerInjectionInterface {
15
16   /**
17    * The app root.
18    *
19    * @var string
20    */
21   protected $root;
22
23   /**
24    * Constructs a new BatchController.
25    *
26    * @param string $root
27    *   The app root.
28    */
29   public function __construct($root) {
30     $this->root = $root;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public static function create(ContainerInterface $container) {
37     return new static(
38       $container->get('app.root')
39     );
40   }
41
42   /**
43    * Returns a system batch page.
44    *
45    * @param \Symfony\Component\HttpFoundation\Request $request
46    *   The current request object.
47    *
48    * @return \Symfony\Component\HttpFoundation\Response|array
49    *   A \Symfony\Component\HttpFoundation\Response object or render array.
50    *
51    * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
52    */
53   public function batchPage(Request $request) {
54     require_once $this->root . '/core/includes/batch.inc';
55     $output = _batch_page($request);
56
57     if ($output === FALSE) {
58       throw new AccessDeniedHttpException();
59     }
60     elseif ($output instanceof Response) {
61       return $output;
62     }
63     elseif (isset($output)) {
64       $title = isset($output['#title']) ? $output['#title'] : NULL;
65       $page = [
66         '#type' => 'page',
67         '#title' => $title,
68         '#show_messages' => FALSE,
69         'content' => $output,
70       ];
71
72       // Also inject title as a page header (if available).
73       if ($title) {
74         $page['header'] = [
75           '#type' => 'page_title',
76           '#title' => $title,
77         ];
78       }
79
80       return $page;
81     }
82   }
83
84   /**
85    * The _title_callback for the system.batch_page.normal route.
86    *
87    * @return string
88    *   The page title.
89    */
90   public function batchPageTitle() {
91     $current_set = _batch_current_set();
92     return !empty($current_set['title']) ? $current_set['title'] : '';
93   }
94
95 }