Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / controller.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/controller.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/controller.twig
new file mode 100644 (file)
index 0000000..45b8398
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Controller;
+
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\Datetime\DateFormatterInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Returns responses for {{ name }} routes.
+ */
+class {{ class }} extends ControllerBase {
+
+  /**
+   * The date formatter service.
+   *
+   * @var \Drupal\Core\Datetime\DateFormatterInterface
+   */
+  protected $dateFormatter;
+
+  /**
+   * Constructs the controller object.
+   *
+   * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
+   *   The date formatter service.
+   */
+  public function __construct(DateFormatterInterface $date_formatter) {
+    $this->dateFormatter = $date_formatter;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('date.formatter')
+    );
+  }
+
+  /**
+   * Builds the response.
+   */
+  public function build() {
+
+    $build['content'] = [
+      '#type' => 'item',
+      '#title' => $this->t('Content'),
+      '#markup' => $this->t('Hello world!'),
+    ];
+
+    $build['date'] = [
+      '#type' => 'item',
+      '#title' => $this->t('Date'),
+      '#markup' => $this->dateFormatter->format(REQUEST_TIME),
+    ];
+
+    return $build;
+  }
+
+}