Same filename and directory in other branches
- 8.9.x core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
- 9 core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
Namespace
Drupal\common_test\Controller
File
core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
View source
<?php
namespace Drupal\common_test\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Core\Extension\ExtensionList;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Response;
class CommonTestController {
public function typeLinkActiveClass() {
return [
'no_query' => [
'#type' => 'link',
'#title' => t('Link with no query string'),
'#url' => Url::fromRoute('<current>'),
'#options' => [
'set_active_class' => TRUE,
],
],
'with_query' => [
'#type' => 'link',
'#title' => t('Link with a query string'),
'#url' => Url::fromRoute('<current>'),
'#options' => [
'query' => [
'foo' => 'bar',
'one' => 'two',
],
'set_active_class' => TRUE,
],
],
'with_query_reversed' => [
'#type' => 'link',
'#title' => t('Link with the same query string in reverse order'),
'#url' => Url::fromRoute('<current>'),
'#options' => [
'query' => [
'one' => 'two',
'foo' => 'bar',
],
'set_active_class' => TRUE,
],
],
];
}
public function jsAndCssQuerystring() {
$module_extension_list = \Drupal::service('extension.list.module');
assert($module_extension_list instanceof ExtensionList);
$attached = [
'#attached' => [
'library' => [
'node/drupal.node',
],
'css' => [
$module_extension_list
->getPath('node') . '/css/node.admin.css' => [],
'/' . $module_extension_list
->getPath('node') . '/node-fake.css?arg1=value1&arg2=value2' => [],
],
],
];
return \Drupal::service('renderer')
->renderRoot($attached);
}
public function destination() {
$destination = \Drupal::destination()
->getAsArray();
$output = "The destination: " . Html::escape($destination['destination']);
return new Response($output);
}
public function attachments() {
\Drupal::state()
->set('common_test.hook_page_attachments.early_rendering', TRUE);
$build = [
'#title' => 'A title',
'content' => [
'#markup' => 'Some content',
],
];
return \Drupal::service('main_content_renderer.html')
->renderResponse($build, \Drupal::requestStack()
->getCurrentRequest(), \Drupal::routeMatch());
}
}
Classes