TestController.php in Tome 8
File
modules/tome_static/tests/modules/tome_test/src/Controller/TestController.php
View source
<?php
namespace Drupal\tome_test\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\HtmlResponse;
use Symfony\Component\HttpFoundation\Request;
class TestController extends ControllerBase {
public function testPage() {
$response = new HtmlResponse();
$response
->setContent('Hello, world');
return $response;
}
public function testComplexPage(Request $request) {
$module_path = drupal_get_path('module', 'tome_test');
return [
'#children' => "<p>Hello, complex world</p>\n<img src=\"/{$module_path}/assets/druplicon-1.png\">\n<img src=\"/{$module_path}/assets/file%20with%20space.png\">\n<img srcset=\"/{$module_path}/assets/srcset-test1.png 320w, /{$module_path}/assets/srcset-test2.png 420w\">\n<source srcset=\"/{$module_path}/assets/srcset-test3.png\">\n<video poster=\"/{$module_path}/assets/poster-test.png\">\n<a href='/random/path'></a>\n<a href='http://www.google.com/external/path'></a>\n<a href='" . $request
->getSchemeAndHttpHost() . "/absolute/path'></a>\n<a href='/path/with/destination?destination=foo&bar=baz'></a>\n<iframe src='/random/iframe'></iframe>\n<img src=\"data:image/jpeg;base64,x\" />\n<meta name=\"twitter:image\" content=\"/twitter_image.png\" />\n<meta property=\"og:image\" content=\"/og_image.png\" />\n<svg><use xlink:href='/use.svg'></use></svg>",
'#attached' => [
'library' => [
'tome_test/complex_page',
],
],
];
}
public function testPageWithPagers() {
return [
'#markup' => '<a href="?page=0">Page 1</a><a href="?page=1">Page 2</a><a href="/foobar?page=2">Page 3</a>',
'#allowed_tags' => [
'a',
],
];
}
public function testPageWithOembed() {
return [
'#markup' => '<iframe src=\'/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3Duqmq5FBP_T0&max_width=0&max_height=0&hash=ON_e21QvgL9euuUSW2TP_s1x62ZmFzzZNuIHbsQpXNg\'></iframe>',
'#allowed_tags' => [
'iframe',
],
];
}
public function fakeOembed() {
return [
'#markup' => 'Hello world!',
];
}
}