7975dcc43869205bd7c8209e5299cd9dab2570c3
[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       $page = [
65         '#type' => 'page',
66         '#show_messages' => FALSE,
67         'content' => $output,
68       ];
69       return $page;
70     }
71   }
72
73   /**
74    * The _title_callback for the system.batch_page.normal route.
75    *
76    * @return string
77    *   The page title.
78    */
79   public function batchPageTitle() {
80     $current_set = _batch_current_set();
81     return !empty($current_set['title']) ? $current_set['title'] : '';
82   }
83
84 }