-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdta_gov_au.theme
624 lines (538 loc) · 22.1 KB
/
dta_gov_au.theme
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Render\FormattableMarkup;
Use Drupal\Component\Utility;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Drupal\taxonomy\Entity\Term;
use Drupal\node\Entity\Node;
use Drupal\book\BookManager;
/**
* Implements HOOK_form_alter()
*
* This changes the performance of the views exposed form used to filter roadmap
* nodes. We do this here because we want the form to be controlled via
* JavaScript rather than OOTB functionality. We don't actually want to remove
* things from the view, just show and hide them, otherwise all the formatting
* gets lost because we need to maintain the grouping structure.
*/
// Helper function.
function _removeElementWithValue($array, $value) {
foreach($array as $subKey => $subArray) {
if($subArray == $value){
unset($array[$subKey]);
}
}
return $array;
}
function dta_gov_au_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if($form_id == 'views_exposed_form' && strpos($form['#id'], 'roadmap' !== false)) {
// Ditch the 'apply' button. The option to submit is also turned off via JS.
unset($form['actions']['submit']);
}
if ($form_id == 'user_login_form') {
// on submit execute the YourThemeName_user_login_submit function
$form['#submit'][] = 'dta_gov_au_user_login_submit';
}
}
function dta_gov_au_user_login_submit($form, &$form_state) {
// redirect use to the homepage (front) on login
$url='<front>';
$form_state->setRedirect($url);
}
/**
* Implements HOOK_preprocess_maintenance_page()
*
* Adds required variables to the maintenance page.
**/
function dta_gov_au_preprocess_maintenance_page(&$variables) {
$form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class) ;
$render = Drupal::service('renderer');
$variables['login_form'] = $render->renderPlain($form);
}
function dta_gov_au_preprocess_html(&$variables) {
if(isset($_ENV['ENVIRONMENT'])) {
$variables['environment'] = $_ENV['ENVIRONMENT'];
} else {
$variables['environment'] = 'local';
}
// IE EDGE SUPPORT
$meta_ie_edge = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge,chrome=1',
),
'#weight' => -999999,
);
// Add header meta tag for IE to head
$variables['page']['#attached']['html_head'][] = [$meta_ie_edge, 'meta_ie_edge'];
}
/**
* Implements hook_preprocess_page().
*
* Adds variables to the page template for book roots, including the
* link to the book root, the book ID and the book root title.
*
**/
function dta_gov_au_preprocess_page(&$variables) {
if(isset($variables['node']->book['bid'])) {
$book = $variables['node']->book;
$bid = $book['bid'];
if ($book['pid'] == 0) {
$book_title = $book['link_title'];
} else {
$book_root = Node::load($bid);
$book_title = $book_root->book['link_title'];
}
$link = Link::fromTextAndUrl($book_title, Url::fromRoute('entity.node.canonical', ['node' => $bid]));
$link = $link->toRenderable();
$link['#attributes']['title'] = t('Go to the title page of the @root_title', ['@root_title' => $book_title]);
$variables['book_link'] = $link;
$variables['bid'] = $bid;
$variables['book_title'] = $book_title;
}
}
/**
* Implements hook_preprocess_menu().
*
* Adds 'is_front' variable to html.html.twig.
* Adds the 'active' class to the active <li>.
*
**/
function dta_gov_au_preprocess_menu(&$variables, $hook) {
try {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}
catch (Exception $e) {
$variables['is_front'] = FALSE;
}
if ($hook == 'menu') {
dta_gov_au_menu_active_item($variables['items']);
$current_path = \Drupal::request()->getRequestUri();
foreach ($variables['items'] as &$item) {
if ($item['in_active_trail']) {
if ($item['url']->toString() == $current_path) {
$item['is_active'] = TRUE;
} elseif (count($item['below'])) {
_dta_gov_au_menu_process_submenu($item['below'], $current_path);
}
}
}
}
}
/**
* Set active and active-trail class for sub-menus recursively.
*/
function _dta_gov_au_menu_process_submenu(&$submenu, $current_path) {
foreach ($submenu as &$item) {
if ($item['in_active_trail']) {
if ($item['url']->toString() == $current_path) {
$item['is_active'] = TRUE;
} elseif (count($item['below'])) {
_dta_gov_au_menu_process_submenu($item['below'], $current_path);
}
}
}
}
function dta_gov_au_preprocess_links__node(&$variables) {
if(isset($variables['links']['book_printer'])) {
$params = $variables['links']['book_printer']['link']['#url']->getRouteParameters();
$nid = $params['node'];
$node = Node::load($nid);
$bid = $node->book['bid'];
$variables['links']['book_printer']['link']['#url']->setRouteParameter('node', $bid);
// We're unsetting this because the link is added in page--book.html.twig and
// hook_preprocess_page() above.
unset($variables['links']['book_printer']);
}
}
function dta_gov_au_menu_active_item(&$items) {
$current_path = \Drupal::request()->getRequestUri();
foreach ($items as $key => $item) {
// if path is current path, set active to li
if ($item['url']->toString() == $current_path) {
// add active linl
$items[$key]['attributes']['class'] = 'active';
}
if (!empty($items[$key]['below'])) {
dta_gov_au_menu_active_item($items[$key]['below']);
}
}
}
/**
* Implements hook_theme_suggestions_block_alter().
*
* As per https://www.drupal.org/docs/8/theming-drupal-8/creating-a-drupal-8-sub-theme-or-sub-theme-of-sub-theme
* to ensure that sub themes inherit block templates.
*/
function dta_gov_au_theme_suggestions_block_alter(&$suggestions, $variables) {
/**
* Adds theme hook suggestions to blocks
*/
if(isset($variables['elements']['#id'])) {
$block_id = $variables['elements']['#id'];
foreach ($suggestions as &$suggestion) {
$suggestion = str_replace('dta_uikit_base_', 'dta_gov_au_', $suggestion);
}
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter
*
* Adds suggestions to forms using the form ID.
*/
function dta_gov_au_theme_suggestions_form_alter(&$suggestions, $variables) {
if(isset($variables['element']['#form_id'])) {
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-', '_', $variables['element']['#form_id']);
}
}
function dta_gov_au_theme_suggestions_container_alter(&$suggestions, $variables) {
if(isset($variables['element']['#form_id'])) {
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-', '_', $variables['element']['#form_id']);
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter
*
* Adds suggestions to text inputs based on the ID of the element.
*/
function dta_gov_au_theme_suggestions_input_alter(&$suggestions, $variables) {
if(isset($variables['element']['#id'])) {
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-','_', $variables['element']['#id']);
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Adds placeholder text to the search bar.
*
**/
function dta_gov_au_form_search_api_page_block_form_alter(&$form, &$form_state, $form_id) {
$search_text = \Drupal::service('path.matcher')->isFrontPage() ? t('What are you looking for today?') : t('Search dta.gov.au');
$form['keys']['#attributes']['placeholder'] = $search_text;
$form['keys']['#attributes']['required'] = TRUE;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Adds honeypot protection to Zendesk form.
*
**/
function dta_gov_au_form_zendesk_support_form_alter(&$form, &$form_state, $form_id) {
honeypot_add_form_protection($form, $form_state, array('honeypot', 'time_restriction'));
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Removes the 'homepage' field from comment forms.
*
**/
function dta_gov_au_form_comment_form_alter(&$form, &$form_state, $form_id) {
$form['author']['homepage']['#access'] = FALSE;
$form['author']['mail']['#title'] = t('Your email address');
$form['author']['name']['#wrapper_attributes']['class'] = ['col-xs-12', 'col-sm-6'];
$form['author']['mail']['#wrapper_attributes']['class'] = ['col-xs-12', 'col-sm-6'];
$form['author']['name']['#attributes']['class'] = ['au-text-input--block'];
$form['author']['mail']['#attributes']['class'] = ['au-text-input--block'];
$form['author']['mail']['#description'] = t('Your email address will not be publicly displayed');
$form['comment_body']['widget']['0']['#title'] = t('Your comment');
$form['actions']['submit']['#value'] = t('Comment');
$form['author_wrapper'] = [
'#type' => 'container',
'#attributes' => [
'class' => ['row'],
],
'name' => $form['author']['name'],
'mail' => $form['author']['mail'],
'#weight' => -97,
];
unset($form['author']['name']);
unset($form['author']['mail']);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the mailchimp signup form.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_sign_up_for_updates_form_1_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['au-text-input--block', 'empty-required'];
$form['mergevars']['FNAME']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['LNAME']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['EMAIL']['#title'] = t('Email address');
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the mailchimp signup form in prod - Form Id is different.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_sign_up_for_updates_form_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['au-text-input--block', 'empty-required'];
$form['mergevars']['FNAME']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['LNAME']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['EMAIL']['#title'] = t('Email address');
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the Style Manual mailchimp signup form.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_sign_up_for_style_manual_updates_form_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['au-text-input--block', 'empty-required'];
$form['mergevars']['FNAME']['#attributes']['class'] = ['au-text-input--block', 'empty-required'];
$form['mergevars']['ORG']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['LNAME']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['EMAIL']['#title'] = t('Email address');
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the Style Manual mailchimp signup form in prod - Form Id is different.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_sign_up_for_style_manual_updates_form_1_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['au-text-input--block', 'empty-required'];
$form['mergevars']['FNAME']['#attributes']['class'] = ['au-text-input--block', 'empty-required'];
$form['mergevars']['ORG']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['LNAME']['#attributes']['class'] = ['au-text-input--block'];
$form['mergevars']['EMAIL']['#title'] = t('Email address');
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the Digital Profession Stream mailchimp signup form.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_digital_professional_stream_form_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['empty-required'];
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the Observatory mailchimp signup form.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_signup_for_observatory_updates_form_1_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['empty-required'];
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the Digital summit mailchimp signup form.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block_digital_summit_signup_form_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['FNAME']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['LNAME']['#attributes']['class'] = ['empty-required'];
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Updates classes on form items in the Coaching women in digital mailchimp signup form.
*
**/
function dta_gov_au_form_mailchimp_signup_subscribe_block__women_in_digital_eoi_form_alter(&$form, &$form_state, $form_id) {
$form['mergevars']['EMAIL']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['LNAME']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['FNAME']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['ROLETITLE']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['LEVEL']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['AGENCY']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['MANAGER']['#attributes']['class'] = ['empty-required'];
$form['mergevars']['GOAL']['#attributes']['class'] = ['empty-required'];
}
/**
*
* Implements hook_theme_suggestions_HOOK_alter
*
* This adds theme hooks to various elements.
*
**/
/* Adds 'item_list__' suggestion to list items in views. */
function dta_gov_au_theme_suggestions_item_list_alter(&$suggestions, &$vars) {
$request['view_id'] = \Drupal::routeMatch()->getRouteObject()->getDefault('view_id');
$request['display_id'] = \Drupal::routeMatch()->getRouteObject()->getDefault('display_id');
if(!empty($request)) {
$suggestions[] = 'item_list__' . $request['view_id'];
$suggestions[] = 'item_list__' . $request['display_id'];
$suggestions[] = 'item_list__' . $request['view_id'] . '__' . $request['display_id'];
}
}
/**
* Implements hook_preprocess_block().
*/
function dta_gov_au_preprocess_block(&$variables) {
if(isset($variables['elements']['#id'])) {
$variables['content']['#attributes']['block'] = $variables['elements']['#id'];
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function dta_gov_au_theme_suggestions_menu_alter(array &$suggestions, array $variables) {
// Remove the block and replace dashes with underscores in the block ID to
// use for the hook name.
if (isset($variables['attributes']['block'])) {
$hook = str_replace(array('block-', '-'), array('', '_'), $variables['attributes']['block']);
$block = \Drupal\block\Entity\Block::load($hook);
$region = $block->getRegion();
$suggestions[] = $variables['theme_hook_original'] . '__' . $region;
$suggestions[] = $variables['theme_hook_original'] . '__' . $hook;
$suggestions[] = $variables['theme_hook_original'] . '__' . $region . '__' . $hook;
}
}
function dta_gov_au_theme_suggestions_page_alter(array &$suggestions, array $variables) {
// Add some more theme suggestions to the page template.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$title = str_replace('-', '_', \Drupal\Component\Utility\Html::cleanCssIdentifier($node->getTitle()));
$type = $node->bundle();
$suggestions[] = $variables['theme_hook_original'] . '__' . $type;
$suggestions[] = $variables['theme_hook_original'] . '__' . \Drupal\Component\Utility\Unicode::strtolower($title);
$suggestions[] = $variables['theme_hook_original'] . '__' . $type . '__' . \Drupal\Component\Utility\Unicode::strtolower($title);
}
}
function dta_gov_au_theme_suggestions_file_link_alter(array &$suggestions, array $variables) {
// Add some more theme suggestions to the file link template.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$title = str_replace('-', '_', \Drupal\Component\Utility\Html::cleanCssIdentifier($node->getTitle()));
$type = $node->bundle();
$suggestions[] = $variables['theme_hook_original'] . '__' . $type;
$suggestions[] = $variables['theme_hook_original'] . '__' . \Drupal\Component\Utility\Unicode::strtolower($title);
$suggestions[] = $variables['theme_hook_original'] . '__' . $type . '__' . \Drupal\Component\Utility\Unicode::strtolower($title);
}
}
/**
* Implements HOOK_preprocess_file_link()
*/
function dta_gov_au_preprocess_file_link(&$variables) {
// Adds useful variables to the file_link template.
if (isset($variables['file'])) {
$variables['file_attributes'] = [
'name' => $variables['file']
->getFilename(),
'size_formatted' => format_size($variables['file']
->getSize()),
'type' => pathinfo($variables['file']
->getFilename(), PATHINFO_EXTENSION),
'url' => file_create_url($variables['file']
->getFileUri()),
];
}
}
function dta_gov_au_theme_suggestions_region_alter(array &$suggestions, array $variables) {
// Add some more theme suggestions to the page template.
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$title = str_replace('-', '_', \Drupal\Component\Utility\Html::cleanCssIdentifier($node->getTitle()));
$type = $node->bundle();
$suggestions[] = $variables['theme_hook_original'] . '__' . $type;
$suggestions[] = $variables['theme_hook_original'] . '__' . \Drupal\Component\Utility\Unicode::strtolower($title);
$suggestions[] = $variables['theme_hook_original'] . '__' . $type . '__' . \Drupal\Component\Utility\Unicode::strtolower($title);
}
}
function dta_gov_au_theme_suggestions_views_view_list_alter(array &$suggestions, array $variables) {
// Adds theme suggestions to the views list template.
$id = $variables['view']->id();
$display = $variables['view']->current_display;
$suggestions[] = $variables['theme_hook_original'] . '__' . (string) $id;
$suggestions[] = $variables['theme_hook_original'] . '__' . (string) $display;
$suggestions[] = $variables['theme_hook_original'] . '__' . (string) $id . '__' . (string) $display;
}
function dta_gov_au_theme_suggestions_views_view_grouping_alter(array &$suggestions, array $variables) {
// Adds theme suggestions to the views grouping template.
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['view']->id();
$suggestions[] = $variables['theme_hook_original'] . '__grouping_level_' . $variables['grouping_level'];
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['view']->id() . '__grouping_level_' . $variables['grouping_level'];
}
function dta_gov_au_theme_suggestions_views_view_unformatted_alter(array &$suggestions, array $variables) {
// Add a theme suggestion to the views unformatted template.
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['view']->id();
}
function dta_gov_au_theme_suggestions_views_exposed_form_alter(array &$suggestions, array $variables) {
// Add a theme suggestion to the views exposed form template.
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-','_', $variables['form']['#id']);
}
/**
* Implements hook_theme_suggestions_HOOK_alter()
* Create theme suggestions for user profile templates
**/
function dta_gov_au_theme_suggestions_user_alter(&$suggestions, array $variables) {
if(isset($variables['elements']['#view_mode'])) {
$viewmode = $variables['elements']['#view_mode'];
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-','_', $viewmode);
}
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if(null !== $node->bundle()) {
$content_type = $node->bundle();
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-','_', $content_type);
if(isset($viewmode)) {
$suggestions[] = $variables['theme_hook_original'] . '__' . str_replace('-','_', $content_type) . '__' . str_replace('-','_', $viewmode);
}
}
}
}
/**
* Implements hook_preprocess_comment
*/
function dta_gov_au_preprocess_comment(&$variables) {
$comment = $variables['elements']['#comment'];
$account = $comment->getOwner();
$username = [
'#theme' => 'username__unlinked',
'#account' => $account,
];
$variables['author'] = \Drupal::service('renderer')->render($username);
$comment_title = $comment->getSubject();
$date = $variables['comment']->getCreatedTime();
$variables['created'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $date);
$datetime = new FormattableMarkup(
'<span class="comments-ago">@datetime ago</span>', [
'@datetime' => $variables['created'],
]
);
$permalink_text = new FormattableMarkup(
'<span class="sr-only"> Permalink to @comment_title</span>', [
'@comment_title' => $comment_title,
]
);
$variables['submitted'] = t('Commented @datetime', array('@datetime' => $datetime));
$variables['permalink'] = Link::fromTextAndUrl(t('#@permalink_text', [
'@permalink_text' => $permalink_text,
]), $comment->permalink());
if (!empty($variables['parent'])) {
$variables['parent'] = t('Replied @datetime to @parent_title by @parent_username', [
'@parent_username' => $variables['parent_author'],
'@parent_title' => $variables['parent_title'],
'@datetime' => $datetime
]);
unset($variables['submitted']);
}
}
/**
* Implements hook_preprocess_book_navigation()
*
* Add some useful variables to the book navigation template.
*/
function dta_gov_au_preprocess_book_navigation(&$variables) {
$book_id = $variables['book_id'];
// Get the book ID and turn it into a URL.
$book_root_url = \Drupal::url('entity.node.canonical', [
'node' => $book_id,
]);
// Get the book title from the book ID.
$book_root_title = \Drupal\node\Entity\Node::load($book_id)->getTitle();
$variables['book_root_url'] = $book_root_url;
$variables['book_root_title'] = $book_root_title;
}
/**
* Implements hook_preprocess_HOOK()
*
* Adds a class to the media embed field to create responsive video.
*/
function dta_gov_au_preprocess_field__media__remote_video(&$variables) {
$variables['items'][0]['content']['#attributes']['class'][] = 'au-responsive-media-vid__item';
}