materiotheme.theme 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support theming in the materio theme.
  5. */
  6. use Drupal\Core\Url;
  7. use Drupal\Core\Link;
  8. use Drupal\Core\Form\FormStateInterface;
  9. use Drupal\Core\Template\Attribute;
  10. use Drupal\Component\Utility\Unicode;
  11. use Drupal\Core\Render\Element;
  12. /**
  13. * Implements hook_page_attachments().
  14. * @param array $attachments
  15. */
  16. // this does not work with themes
  17. // function materiotheme_page_attachments(array &$attachments) {
  18. // dpm('materiotheme_page_attachments', $attachments);
  19. // }
  20. /**
  21. * Prepares variables for HTML document templates.
  22. *
  23. * Default template: html.html.twig.
  24. *
  25. * @param array $variables
  26. * An associative array containing:
  27. * - page: A render element representing the page.
  28. */
  29. function materiotheme_preprocess_html(&$vars) {
  30. // $head_title = $vars['head_title'];
  31. // dpm($vars);
  32. $site_config = \Drupal::config('system.site');
  33. // dpm($site_config->get('slogan'));
  34. // array_push($head_title, [
  35. // 'name' => $site_config->get('name'),
  36. // ]);
  37. // $vars['head_title'] = $head_title;
  38. // $title = "The new title";
  39. // $request = \Drupal::request();
  40. // if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
  41. // $route->setDefault('_title', $title);
  42. // }
  43. global $base_url;
  44. $theme = \Drupal::theme()->getActiveTheme();
  45. $vars['#attached']['drupalSettings']['path']['themePath'] = $base_url .'/'. $theme->getPath();
  46. $description = [
  47. '#tag' => 'meta',
  48. '#attributes' => [
  49. 'name' => 'description',
  50. 'content' => $site_config->get('slogan'),
  51. ],
  52. ];
  53. $vars['page']['#attached']['html_head'][] = [$description, 'description'];
  54. // $gv = [
  55. // '#tag' => 'meta',
  56. // '#attributes' => [
  57. // 'name' => 'google-site-verification',
  58. // 'content' => "Y6PSbMfj67bXtMRAT-mFTAxrIeZPzC5jWSpH3M7yhkk",
  59. // ],
  60. // ];
  61. // $vars['page']['#attached']['html_head'][] = [$gv, "google-site-verification"];
  62. }
  63. function materiotheme_preprocess_page(&$vars){
  64. // dsm($vars, 'vars');
  65. }
  66. // function materiotheme_preprocess_node(&$vars){
  67. // $node = $vars['elements']['#node'];
  68. // $options = ['absolute' => TRUE];
  69. // $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options);
  70. // $system_path = $url->getInternalPath();
  71. // $vars['link_attributes'] = new Attribute(array(
  72. // 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path
  73. // ));
  74. // }
  75. // function materiotheme_preprocess_node_materiau_teaser(&$vars){
  76. // $vars['attributes']['class'] = 'card';
  77. // kint($vars['attributes']);
  78. // }
  79. /**
  80. * Implements hook_form_alter
  81. */
  82. function materiotheme_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  83. // dpm($form_id, 'form_id');
  84. // dpm($form, 'form');
  85. $form['name']['#attributes']['placeholder'] = (string) $form['name']['#title'];
  86. unset($form['name']['#title']);
  87. $form['pass']['#attributes']['placeholder'] = (string) $form['pass']['#title'];
  88. unset($form['pass']['#title']);
  89. }
  90. /**
  91. * Implements hook_theme_suggestions_HOOK_alter().
  92. */
  93. /**
  94. * Prepares variables for image formatter templates.
  95. *
  96. * Default template: image-formatter.html.twig.
  97. *
  98. * @param array $variables
  99. * An associative array containing:
  100. * - item: An ImageItem object.
  101. * - item_attributes: An optional associative array of html attributes to be
  102. * placed in the img tag.
  103. * - image_style: An optional image style.
  104. * - url: An optional \Drupal\Core\Url object.
  105. */
  106. // function materiotheme_preprocess_image_formatter(&$vars){
  107. // if(isset($vars['url'])){
  108. // $system_path = $vars['url']->getInternalPath();
  109. // $vars['link_attributes'] = new Attribute(array(
  110. // 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path,
  111. // 'class' => array('ajax-link')
  112. // ));
  113. // // dpm($vars);
  114. // }
  115. // }
  116. // function materiotheme_preprocess_links__language_block(&$vars){
  117. // // dpm($vars);
  118. // // foreach ($vars['links'] as $lang_code => $link) {
  119. // // $vars['links'][$lang_code]['text'] = $lang_code;
  120. // // $vars['links'][$lang_code]['link']['#title'] = $lang_code;
  121. // // }
  122. // }