Skip to content

Instantly share code, notes, and snippets.

@netlooker
Created April 23, 2018 09:42
Show Gist options
  • Save netlooker/c76fc96b6e829cd3501bc49bca87c455 to your computer and use it in GitHub Desktop.
Save netlooker/c76fc96b6e829cd3501bc49bca87c455 to your computer and use it in GitHub Desktop.
ECL Tables - helper controller
Index: modules/oe_theme_demo/oe_theme_demo.routing.yml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/oe_theme_demo/oe_theme_demo.routing.yml (date 1523027549000)
+++ modules/oe_theme_demo/oe_theme_demo.routing.yml (date 1523027549000)
@@ -0,0 +1,7 @@
+oe_theme_demo.example:
+ path: '/oe-theme-demo/example'
+ defaults:
+ _title: 'Example'
+ _controller: '\Drupal\oe_theme_demo\Controller\OpenEuropaThemeDemoController::build'
+ requirements:
+ _permission: 'access content'
Index: modules/oe_theme_demo/src/Controller/OpenEuropaThemeDemoController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/oe_theme_demo/src/Controller/OpenEuropaThemeDemoController.php (date 1524474527000)
+++ modules/oe_theme_demo/src/Controller/OpenEuropaThemeDemoController.php (date 1524474527000)
@@ -0,0 +1,88 @@
+<?php
+
+namespace Drupal\oe_theme_demo\Controller;
+
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\Datetime\DateFormatterInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Returns responses for OpenEuropa Theme Demo routes.
+ */
+class OpenEuropaThemeDemoController 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() {
+ // Set up a render array.
+ $header = [
+ [
+ 'data' => 'Name',
+ 'field' => 'name',
+ 'sort' => 'asc',
+ ],
+ [
+ 'data' => 'Registration date',
+ 'field' => 'date',
+ ],
+ [
+ 'data' => 'Email',
+ 'field' => 'email',
+ ],
+ ];
+ $data = [
+ [
+ 'name' => 'John Doe',
+ 'date' => '01/01/2016',
+ 'email' => '[email protected]',
+ ],
+ [
+ 'name' => 'Jane Doe',
+ 'date' => '06/12/2016',
+ 'email' => '[email protected]',
+ ],
+ [
+ 'name' => 'Jack Doe',
+ 'date' => '03/05/2017',
+ 'email' => '[email protected]',
+ ],
+ ];
+
+ $build[] = [
+ '#theme' => 'table',
+ '#caption' => 'Default table',
+ '#header' => $header,
+ '#rows' => $data,
+ ];
+
+ return $build;
+ }
+
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment