Skip to content

Commit 5f14947

Browse files
smulvihillsylus
authored andcommitted
Issue #3277987 by smulvih2: Add common book page template fix to starterkit
1 parent ca24276 commit 5f14947

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

starterkits/wxt/THEMENAME.theme

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Place your custom PHP code in this file.
88
*/
99

10+
use Drupal\node\NodeInterface;
11+
1012
/**
1113
* Implements hook_theme_suggestions_HOOK_alter().
1214
*/
@@ -17,3 +19,33 @@ function THEMENAME_theme_suggestions_block_alter(&$suggestions, $variables) {
1719
$suggestion = str_replace('THEMENAME_', 'wxt_bootstrap_', $suggestion);
1820
}
1921
}
22+
23+
/**
24+
* Implements hook_theme_suggestions_HOOK_alter().
25+
*/
26+
function THEMENAME_theme_suggestions_page_alter(array &$suggestions, array $variables) {
27+
$moduleHandler = \Drupal::service('module_handler');
28+
29+
if ($moduleHandler->moduleExists('wxt_ext_book')) {
30+
$node = \Drupal::routeMatch()->getParameter('node');
31+
32+
if ($node instanceof NodeInterface) {
33+
if (!empty($node->book) && $node->book['bid'] != 0) {
34+
/** @var \Drupal\wxt_library\LibraryService $wxt */
35+
$wxt = \Drupal::service('wxt_library.service_wxt');
36+
$wxt_active = $wxt->getLibraryName();
37+
38+
if ($node->book['bid'] == $node->id()) {
39+
// Theme book index page
40+
$suggestions[] = $variables['theme_hook_original'] . '__book_index';
41+
$suggestions[] = $variables['theme_hook_original'] . '__' . $wxt_active . '__book_index';
42+
}
43+
else {
44+
// Theme book child page
45+
$suggestions[] = $variables['theme_hook_original'] . '__book_page';
46+
$suggestions[] = $variables['theme_hook_original'] . '__' . $wxt_active . '__book_page';
47+
}
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)