3 namespace Drupal\router_test;
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;
12 * Test controllers that are intended to be wrapped in a main controller.
14 class TestContent extends ControllerBase {
19 * @var \Symfony\Component\HttpKernel\HttpKernelInterface
21 protected $httpKernel;
24 * Constructs a TestContent instance.
26 public function __construct(HttpKernelInterface $http_kernel) {
27 $this->httpKernel = $http_kernel;
33 public static function create(ContainerInterface $container) {
34 return new static($container->get('http_kernel'));
38 * Provides example content for testing route enhancers.
40 public function test1() {
41 return ['#markup' => 'abcde'];
45 * Provides example content for route specific authentication.
48 * The user name of the current logged in user.
50 public function test11() {
51 $account = $this->currentUser();
52 return ['#markup' => $account->getUsername()];
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()];
62 * Uses a subrequest to determine the content.
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());
68 return $this->httpKernel->handle($request, HttpKernelInterface::SUB_REQUEST);