class TestingExampleController in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/testing_example/src/Controller/TestingExampleController.php \Drupal\testing_example\Controller\TestingExampleController
Controller for testing_example module.
This class uses the DescriptionTemplateTrait to display text we put in the templates/description.html.twig file. We render out the text via its description() method, and set up our routing to point to TestingExampleController::description().
Hierarchy
- class \Drupal\testing_example\Controller\TestingExampleController uses DescriptionTemplateTrait
Expanded class hierarchy of TestingExampleController
File
- testing_example/
src/ Controller/ TestingExampleController.php, line 15
Namespace
Drupal\testing_example\ControllerView source
class TestingExampleController {
use DescriptionTemplateTrait;
/**
* {@inheritdoc}
*/
protected function getModuleName() {
return 'testing_example';
}
/**
* Generate a render array for the Simpletest description.
*
* @return array
* A render array.
*/
public function simpletestDescription() {
$template_file = drupal_get_path('module', 'testing_example') . '/templates/simpletest.description.html.twig';
$build = [
'description' => [
'#type' => 'inline_template',
'#template' => file_get_contents($template_file),
],
];
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DescriptionTemplateTrait:: |
public | function | Generate a render array with our templated content. | |
DescriptionTemplateTrait:: |
protected | function | Get full path to the template. | |
DescriptionTemplateTrait:: |
protected | function | Variables to act as context to the twig template file. | 1 |
TestingExampleController:: |
protected | function |
Name of our module. Overrides DescriptionTemplateTrait:: |
|
TestingExampleController:: |
public | function | Generate a render array for the Simpletest description. |