TestControllers.php in Drupal 10
File
core/modules/system/tests/modules/menu_test/src/TestControllers.php
View source
<?php
namespace Drupal\menu_test;
use Drupal\Component\Render\FormattableMarkup;
use Symfony\Component\HttpFoundation\Request;
class TestControllers {
public function testLogin() {
return [
'#markup' => 'This is TestControllers::testLogin.',
];
}
public function test1() {
return [
'#markup' => 'test1',
];
}
public function test2() {
return [
'#markup' => 'test2',
];
}
public function testSession(Request $request) {
$counter = $request
->getSession()
->get('menu_test', 0);
$request
->getSession()
->set('menu_test', ++$counter);
return [
'#markup' => new FormattableMarkup('Session menu_test is @count', [
'@count' => $counter,
]),
];
}
public function testDerived() {
return [
'#markup' => 'testDerived',
];
}
public function testDefaults($placeholder = NULL) {
if ($placeholder) {
return [
'#markup' => new FormattableMarkup("Sometimes there is a placeholder: '@placeholder'.", [
'@placeholder' => $placeholder,
]),
];
}
else {
return [
'#markup' => 'Sometimes there is no placeholder.',
];
}
}
public function testContextual() {
return [
'#markup' => 'testContextual',
'stuff' => [
'#type' => 'contextual_links',
'#contextual_links' => [
'menu_test_menu' => [
'route_parameters' => [
'bar' => 1,
],
],
],
],
];
}
}