class TestingExampleController

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of TestingExampleController

File

modules/testing_example/src/Controller/TestingExampleController.php, line 18

Namespace

Drupal\testing_example\Controller
View source
class TestingExampleController implements ContainerInjectionInterface {
  use DescriptionTemplateTrait;
  
  /**
   * The module extension list.
   *
   * @var \Drupal\Core\Extension\ModuleExtensionList
   */
  protected $moduleExtensionList;
  // phpcs:disable Drupal.Files.LineLength.TooLong
  
  /**
   * Constructs a new \Drupal\testing_example\Controller\TestingExampleController.
   *
   * @param \Drupal\Core\Extension\ModuleExtensionList $module_extension
   *   The module extension list.
   */
  public function __construct(ModuleExtensionList $module_extension) {
    $this->moduleExtensionList = $module_extension;
  }
  //phpcs:enable
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container->get('extension.list.module'));
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getModuleName() {
    return 'testing_example';
  }
  
  /**
   * Generate a render array for the Simpletest description.
   *
   * @return array
   *   A render array.
   */
  public function phpUnitDescription() {
    $template_file = $this->moduleExtensionList
      ->getPath('testing_example') . '/templates/phpunit.description.html.twig';
    $build = [
      'description' => [
        '#type' => 'inline_template',
        '#template' => file_get_contents($template_file),
      ],
    ];
    return $build;
  }
  
  /**
   * Generate a render array for the Simpletest description.
   *
   * @return array
   *   A render array.
   */
  public function simpletestDescription() {
    $template_file = $this->moduleExtensionList
      ->getPath('testing_example') . '/templates/simpletest.description.html.twig';
    $build = [
      'description' => [
        '#type' => 'inline_template',
        '#template' => file_get_contents($template_file),
      ],
    ];
    return $build;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DescriptionTemplateTrait::description public function Generate a render array with our templated content.
DescriptionTemplateTrait::getDescriptionTemplatePath protected function Get full path to the template.
DescriptionTemplateTrait::getDescriptionVariables protected function Variables to act as context to the twig template file. 1
TestingExampleController::$moduleExtensionList protected property The module extension list.
TestingExampleController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
TestingExampleController::getModuleName protected function Name of our module. Overrides DescriptionTemplateTrait::getModuleName
TestingExampleController::phpUnitDescription public function Generate a render array for the Simpletest description.
TestingExampleController::simpletestDescription public function Generate a render array for the Simpletest description.
TestingExampleController::__construct public function Constructs a new \Drupal\testing_example\Controller\TestingExampleController.