f392a81e85e3a8b7c1486dce42450b24348f0f51
[yaffs-website] / TestContent.php
1 <?php
2
3 namespace Drupal\router_test;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\user\UserInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\HttpFoundation\Request;
9 use Symfony\Component\HttpKernel\HttpKernelInterface;
10
11 /**
12  * Test controllers that are intended to be wrapped in a main controller.
13  */
14 class TestContent extends ControllerBase {
15
16   /**
17    * The HTTP kernel.
18    *
19    * @var \Symfony\Component\HttpKernel\HttpKernelInterface
20    */
21   protected $httpKernel;
22
23   /**
24    * Constructs a TestContent instance.
25    */
26   public function __construct(HttpKernelInterface $http_kernel) {
27     $this->httpKernel = $http_kernel;
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public static function create(ContainerInterface $container) {
34     return new static($container->get('http_kernel'));
35   }
36
37   /**
38    * Provides example content for testing route enhancers.
39    */
40   public function test1() {
41     return ['#markup' => 'abcde'];
42   }
43
44   /**
45    * Provides example content for route specific authentication.
46    *
47    * @returns string
48    *   The user name of the current logged in user.
49    */
50   public function test11() {
51     $account = $this->currentUser();
52     return ['#markup' => $account->getUsername()];
53   }
54
55   public function testAccount(UserInterface $user) {
56     $current_user_name = $this->currentUser()->getUsername();
57     $this->currentUser()->setAccount($user);
58     return ['#markup' => $current_user_name . ':' . $user->getUsername()];
59   }
60
61   /**
62    * Uses a subrequest to determine the content.
63    */
64   public function subrequestTest(UserInterface $user) {
65     $request = \Drupal::request();
66     $request = Request::create('/router_test/test13/' . $user->id(), 'GET', $request->query->all(), $request->cookies->all(), [], $request->server->all());
67
68     return $this->httpKernel->handle($request, HttpKernelInterface::SUB_REQUEST);
69   }
70
71 }