45b839821f47b4d2fb4decfa32a59e292c13d006
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / controller.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Datetime\DateFormatterInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * Returns responses for {{ name }} routes.
11  */
12 class {{ class }} extends ControllerBase {
13
14   /**
15    * The date formatter service.
16    *
17    * @var \Drupal\Core\Datetime\DateFormatterInterface
18    */
19   protected $dateFormatter;
20
21   /**
22    * Constructs the controller object.
23    *
24    * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
25    *   The date formatter service.
26    */
27   public function __construct(DateFormatterInterface $date_formatter) {
28     $this->dateFormatter = $date_formatter;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public static function create(ContainerInterface $container) {
35     return new static(
36       $container->get('date.formatter')
37     );
38   }
39
40   /**
41    * Builds the response.
42    */
43   public function build() {
44
45     $build['content'] = [
46       '#type' => 'item',
47       '#title' => $this->t('Content'),
48       '#markup' => $this->t('Hello world!'),
49     ];
50
51     $build['date'] = [
52       '#type' => 'item',
53       '#title' => $this->t('Date'),
54       '#markup' => $this->dateFormatter->format(REQUEST_TIME),
55     ];
56
57     return $build;
58   }
59
60 }