/
AxeController.php
99 lines (79 loc) · 2.25 KB
/
AxeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @file
* Contains \Drupal\axe\Controller\AxeController.
*/
namespace Drupal\axe\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Returns responses for axe module routes.
*/
class AxeController extends ControllerBase {
/**
* Builds a axe page.
*/
public function build() {
// Sanity Check 1. Somethings Printing.
// return 'Howdy Austin';
// Sanity Check 2. Renderable Array.
// return array(
// '#theme' => 'item_list',
// '#items' => array(
// 'beaver',
// 'pine beetle',
// 'lumber jack',
// ),
// );
// Quick Inline Template test. Sanity Check 3.
// Creat some link render array.
// $render_array = array(
// '#type' => 'link',
// '#title' => "Y'all",
// '#href' => '<front>',
// '#attributes' => array('rel' => 'home', 'title' => t('Home')),
// );
// $users = array(
// array(
// 'name' => '<taggy mc="taggerson">',
// ),
// array(
// 'name' => 'Jay Pritchett',
// ),
// array(
// 'name' => 'Gloria Delgado-Pritchett',
// )
// );
// // Render quick inline.
// return $this->renderInline('
// Hello {{ name }}!
// {% for user in users %}
// <li>{{ user.name|e }}</li>
// {% endfor %}',
// array(
// 'name' => $render_array,
// 'users' => $users,
// )
// );
}
/**
* Inline Rendering Twig
* @return string
*/
function renderInline($template = '', $data = array()) {
// 'Pilfer' the twig service.
$twig = \Drupal::service('twig');
// Create a new string loader(inline template).
// @see http://twig.sensiolabs.org/api/master/Twig_Loader_String.html
// and http://twig.sensiolabs.org/doc/api.html#twig-loader-string
$loader = new \Twig_Loader_String();
// Sore the old template loader so we don't break things.
$old_loader = $twig->getLoader();
// Set the new twig string template loader.
$twig->setLoader($loader);
// Render the inline template with the name link renderable array variable.
$output = $twig->render($template, $data);
// Set the old loader so templates still work.
$twig->setLoader($old_loader);
return $output;
}
}