Skip to content

Commit 7350b03

Browse files
jalpeshpaul-m
authored andcommitted
Issue #2883724 by jalpesh: Convert JsExampleController to use DescriptionTemplateTrait
1 parent 5f4d8de commit 7350b03

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

js_example/js_example.routing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ js_example.info:
22
path: '/examples/js-example'
33
defaults:
44
_title: 'JavaScript Example Information'
5-
_controller: '\Drupal\js_example\Controller\JsExampleController::info'
5+
_controller: '\Drupal\js_example\Controller\JsExampleController::description'
66
requirements:
77
_permission: 'access content'
88

js_example/src/Controller/JsExampleController.php

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,22 @@
22

33
namespace Drupal\js_example\Controller;
44

5-
use Drupal\Core\Controller\ControllerBase;
5+
use Drupal\examples\Utility\DescriptionTemplateTrait;
66

77
/**
8-
* Controller for js_example pages.
8+
* Controller for Hooks example description page.
99
*
10-
* @ingroup js_example
10+
* This class uses the DescriptionTemplateTrait to display text we put in the
11+
* templates/description.html.twig file.
1112
*/
12-
class JsExampleController extends ControllerBase {
13+
class JsExampleController {
14+
use DescriptionTemplateTrait;
1315

1416
/**
15-
* Example info page.
16-
*
17-
* @return array
18-
* A renderable array.
17+
* {@inheritdoc}
1918
*/
20-
public function info() {
21-
$build['content'] = [
22-
'first_line' => [
23-
'#prefix' => '<p>',
24-
'#markup' => 'Drupal includes jQuery and jQuery UI.',
25-
'#suffix' => '</p>',
26-
],
27-
'second_line' => [
28-
'#prefix' => '<p>',
29-
'#markup' => 'We have two examples of using these:',
30-
'#suffix' => '</p>',
31-
],
32-
'examples_list' => [
33-
'#theme' => 'item_list',
34-
'#items' => [
35-
'An accordion-style section reveal effect. This demonstrates calling a jQuery UI function using Drupal&#39;s rendering system.',
36-
'Sorting according to numeric &#39;weight.&#39; This demonstrates attaching your own JavaScript code to individual page elements using Drupal&#39;s rendering system.',
37-
],
38-
'#type' => 'ol',
39-
],
40-
];
41-
42-
return $build;
19+
protected function getModuleName() {
20+
return 'js_example';
4321
}
4422

4523
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{#
2+
3+
Description text for the JavaScript Example.
4+
5+
#}
6+
7+
{% trans %}
8+
9+
<p>Drupal includes jQuery and jQuery UI.</p>
10+
11+
<p>We have two examples of using these:</p>
12+
13+
<ol>
14+
<li>
15+
<p>An accordion-style section reveal effect: This demonstrates calling a jQuery
16+
UI function using Drupal rendering system.
17+
</li>
18+
<li>
19+
<p>Sorting according to numeric weight: This demonstrates attaching your own
20+
JavaScript code to individual page elements using Drupal rendering system.</p>
21+
</li>
22+
</ol>
23+
{% endtrans %}

0 commit comments

Comments
 (0)