74ea9c1e57e79434f85ba2c48bf784632486539e
[yaffs-website] / web / core / modules / block / src / Controller / BlockListController.php
1 <?php
2
3 namespace Drupal\block\Controller;
4
5 use Drupal\Core\Entity\Controller\EntityListController;
6 use Drupal\Core\Extension\ThemeHandlerInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\HttpFoundation\Request;
9 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
11 /**
12  * Defines a controller to list blocks.
13  */
14 class BlockListController extends EntityListController {
15
16   /**
17    * The theme handler.
18    *
19    * @var \Drupal\Core\Extension\ThemeHandlerInterface
20    */
21   protected $themeHandler;
22
23   /**
24    * Constructs the BlockListController.
25    *
26    * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
27    *   The theme handler.
28    */
29   public function __construct(ThemeHandlerInterface $theme_handler) {
30     $this->themeHandler = $theme_handler;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public static function create(ContainerInterface $container) {
37     return new static(
38       $container->get('theme_handler')
39     );
40   }
41
42   /**
43    * Shows the block administration page.
44    *
45    * @param string|null $theme
46    *   Theme key of block list.
47    * @param \Symfony\Component\HttpFoundation\Request $request
48    *   The current request.
49    *
50    * @return array
51    *   A render array as expected by drupal_render().
52    */
53   public function listing($theme = NULL, Request $request = NULL) {
54     $theme = $theme ?: $this->config('system.theme')->get('default');
55     if (!$this->themeHandler->hasUi($theme)) {
56       throw new NotFoundHttpException();
57     }
58
59     return $this->entityManager()->getListBuilder('block')->render($theme, $request);
60   }
61
62 }