Drupal 8 Site using Vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.5 KiB

  1. <?php
  2. use \Drupal\Component\Utility\Html;
  3. /**
  4. * @file
  5. * Functions to support theming in the vue_js theme.
  6. */
  7. /**
  8. * Implements hook_preprocess_HOOK() for html.html.twig.
  9. */
  10. function vue_js_preprocess_html(array &$variables) {
  11. /* Add class to html tag */
  12. //$variables['html_attributes']->addClass('no-js');
  13. // Don't display the site name twice on the front page (and potentially others)
  14. /*if (isset($variables['head_title_array']['title']) && isset($variables['head_title_array']['name']) && ($variables['head_title_array']['title'] == $variables['head_title_array']['name'])) {
  15. $variables['head_title'] = $variables['head_title_array']['name'];
  16. }*/
  17. }
  18. /**
  19. * Implements hook_page_attachments_alter().
  20. */
  21. function vue_js_page_attachments_alter(array &$page) {
  22. // Tell IE to use latest rendering engine (not to use compatibility mode).
  23. /*$ie_edge = [
  24. '#type' => 'html_tag',
  25. '#tag' => 'meta',
  26. '#attributes' => [
  27. 'http-equiv' => 'X-UA-Compatible',
  28. 'content' => 'IE=edge',
  29. ],
  30. ];
  31. $page['#attached']['html_head'][] = [$ie_edge, 'ie_edge'];*/
  32. }
  33. /**
  34. * Implements hook_preprocess_page() for page.html.twig.
  35. */
  36. function vue_js_preprocess_page(array &$variables) {
  37. $route = \Drupal::routeMatch()->getRouteName();
  38. if (stripos($route, 'layout_builder.') !== FALSE) {
  39. $variables['#attached']['library'][] = 'vue_js/layout-builder-prettier';
  40. } else {
  41. // Not a Layout builder route, so let's mark to hide contextual links
  42. $variables['attributes']['class'][] = 'hide-contextual-links';
  43. }
  44. }
  45. /**
  46. * Implements hook_theme_suggestions_page_alter().
  47. */
  48. function vue_js_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  49. }
  50. /**
  51. * Implements hook_theme_suggestions_node_alter().
  52. */
  53. function vue_js_theme_suggestions_node_alter(array &$suggestions, array $variables) {
  54. /*$node = $variables['elements']['#node'];
  55. if ($variables['elements']['#view_mode'] == "full") {
  56. }*/
  57. }
  58. /**
  59. * Implements hook_preprocess_HOOK() for Block document templates.
  60. */
  61. function vue_js_preprocess_block(array &$variables) {
  62. if (isset($variables['content']['#block_content'])) {
  63. /* @var $block \Drupal\block_content\Entity\BlockContent */
  64. $block = $variables['content']['#block_content'];
  65. $type = $block->bundle();
  66. $variables['block'] = $variables['content']['#block_content'];
  67. $function = __FUNCTION__ . "_{$type}";
  68. if (function_exists($function)) {
  69. $function($variables);
  70. }
  71. }
  72. }
  73. /**
  74. * Implements hook_theme_suggestions_field_alter().
  75. */
  76. function vue_js_theme_suggestions_field_alter(array &$suggestions, array $variables) {
  77. /*$element = $variables['element'];
  78. $suggestions[] = 'field__' . $element['#view_mode'];
  79. $suggestions[] = 'field__' . $element['#view_mode'] . '__' . $element['#field_name'];*/
  80. }
  81. /**
  82. * Implements hook_theme_suggestions_field_alter().
  83. */
  84. function vue_js_theme_suggestions_fieldset_alter(array &$suggestions, array $variables) {
  85. /*$element = $variables['element'];
  86. if (isset($element['#attributes']['class']) && in_array('form-composite', $element['#attributes']['class'])) {
  87. $suggestions[] = 'fieldset__form_composite';
  88. }*/
  89. }
  90. /**
  91. * Implements hook_preprocess_node().
  92. */
  93. function vue_js_preprocess_node(array &$variables) {
  94. /* @var \Drupal\node\Entity\Node $node */
  95. $node = $variables['node'];
  96. $type = $node->bundle();
  97. $view_mode = $variables['view_mode'] ?? NULL;
  98. $variables['attributes']['class'][] = 'node';
  99. $variables['attributes']['class'][] = 'node__' . Html::cleanCssIdentifier($type);
  100. if ($view_mode) {
  101. $variables['attributes']['class'][] = 'node__' . Html::cleanCssIdentifier($type) . '__view_mode_' . Html::cleanCssIdentifier($view_mode);
  102. }
  103. $function = __FUNCTION__ . "_{$type}";
  104. if (function_exists($function)) {
  105. $function($variables);
  106. }
  107. }
  108. /**
  109. * Implements hook_preprocess_paragraph().
  110. */
  111. function vue_js_preprocess_paragraph(array &$variables) {
  112. /* @var \Drupal\paragraphs\Entity\ParagraphsType $paragraph_type */
  113. $paragraph_type = $variables['elements']['#paragraph']->getParagraphType();
  114. $function = __FUNCTION__ . "_{$paragraph_type->id()}";
  115. if (function_exists($function)) {
  116. $function($variables);
  117. }
  118. }
  119. function nazarene_org_preprocess_media(array &$variables) {
  120. $bundle = $variables['media']->bundle();
  121. $function = __FUNCTION__ . "_{$bundle}";
  122. if (function_exists($function)) {
  123. $function($variables);
  124. }
  125. }
  126. /**
  127. * Implements hook_theme_suggestions_views_view_alter().
  128. */
  129. function vue_js_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
  130. }
  131. /**
  132. * Implements hook_preprocess_form().
  133. */
  134. function vue_js_preprocess_form(array &$variables) {
  135. //$variables['attributes']['novalidate'] = 'novalidate';
  136. }
  137. /**
  138. * Implements hook_preprocess_select().
  139. */
  140. function vue_js_preprocess_select(array &$variables) {
  141. //$variables['attributes']['class'][] = 'select-chosen';
  142. }
  143. /**
  144. * Implements hook_preprocess_field().
  145. */
  146. function vue_js_preprocess_field(array &$variables, $hook) {
  147. /*switch ($variables['element']['#field_name']) {
  148. }*/
  149. }
  150. /**
  151. * Implements hook_preprocess_details().
  152. */
  153. function vue_js_preprocess_details(array &$variables) {
  154. /*$variables['attributes']['class'][] = 'details';
  155. $variables['summary_attributes']['class'] = 'summary';*/
  156. }
  157. /**
  158. * Implements hook_theme_suggestions_details_alter().
  159. */
  160. function vue_js_theme_suggestions_details_alter(array &$suggestions, array $variables) {
  161. }
  162. /**
  163. * Implements hook_preprocess_menu_local_task().
  164. */
  165. function vue_js_preprocess_menu_local_task(array &$variables) {
  166. //$variables['element']['#link']['url']->setOption('attributes', ['class'=>'rounded']);
  167. }