class TestContent
Same name and namespace in other branches
- 11.x core/modules/system/tests/modules/router_test_directory/src/TestContent.php \Drupal\router_test\TestContent
- 10 core/modules/system/tests/modules/router_test_directory/src/TestContent.php \Drupal\router_test\TestContent
- 8.9.x core/modules/system/tests/modules/router_test_directory/src/TestContent.php \Drupal\router_test\TestContent
Test controllers that are intended to be wrapped in a main controller.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\router_test\TestContent extends \Drupal\Core\Controller\ControllerBase
Expanded class hierarchy of TestContent
File
-
core/
modules/ system/ tests/ modules/ router_test_directory/ src/ TestContent.php, line 14
Namespace
Drupal\router_testView source
class TestContent extends ControllerBase {
/**
* The HTTP kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* Constructs a TestContent instance.
*/
public function __construct(HttpKernelInterface $http_kernel) {
$this->httpKernel = $http_kernel;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('http_kernel'));
}
/**
* Provides example content for testing route enhancers.
*/
public function test1() {
return [
'#markup' => 'abcde',
];
}
/**
* Provides example content for route specific authentication.
*
* @returns string
* The user name of the current logged in user.
*/
public function test11() {
$account = $this->currentUser();
return [
'#markup' => $account->getAccountName(),
];
}
public function testAccount(UserInterface $user) {
$current_user_name = $this->currentUser()
->getAccountName();
$this->currentUser()
->setAccount($user);
return [
'#markup' => $current_user_name . ':' . $user->getAccountName(),
];
}
/**
* Uses a subrequest to determine the content.
*/
public function subrequestTest(UserInterface $user) {
$request = \Drupal::request();
$request = Request::create('/router_test/test13/' . $user->id(), 'GET', $request->query
->all(), $request->cookies
->all(), [], $request->server
->all());
return $this->httpKernel
->handle($request, HttpKernelInterface::SUB_REQUEST);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.