materiotheme.theme 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. global $base_url;
  39. $theme = \Drupal::theme()->getActiveTheme();
  40. $vars['#attached']['drupalSettings']['path']['themePath'] = $base_url .'/'. $theme->getPath();
  41. $description = [
  42. '#tag' => 'meta',
  43. '#attributes' => [
  44. 'name' => 'description',
  45. 'content' => $site_config->get('slogan'),
  46. ],
  47. ];
  48. $vars['page']['#attached']['html_head'][] = [$description, 'description'];
  49. // $gv = [
  50. // '#tag' => 'meta',
  51. // '#attributes' => [
  52. // 'name' => 'google-site-verification',
  53. // 'content' => "Y6PSbMfj67bXtMRAT-mFTAxrIeZPzC5jWSpH3M7yhkk",
  54. // ],
  55. // ];
  56. // $vars['page']['#attached']['html_head'][] = [$gv, "google-site-verification"];
  57. }
  58. function materiotheme_preprocess_page(&$vars){
  59. // dsm($vars, 'vars');
  60. }
  61. // function materiotheme_preprocess_node(&$vars){
  62. // $node = $vars['elements']['#node'];
  63. // $options = ['absolute' => TRUE];
  64. // $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options);
  65. // $system_path = $url->getInternalPath();
  66. // $vars['link_attributes'] = new Attribute(array(
  67. // 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path
  68. // ));
  69. // }
  70. /**
  71. * Implements hook_form_alter
  72. */
  73. function materiotheme_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  74. // dpm($form_id, 'form_id');
  75. // dpm($form, 'form');
  76. $form['name']['#attributes']['placeholder'] = (string) $form['name']['#title'];
  77. unset($form['name']['#title']);
  78. $form['pass']['#attributes']['placeholder'] = (string) $form['pass']['#title'];
  79. unset($form['pass']['#title']);
  80. }
  81. /**
  82. * Implements hook_theme_suggestions_HOOK_alter().
  83. */
  84. /**
  85. * Prepares variables for image formatter templates.
  86. *
  87. * Default template: image-formatter.html.twig.
  88. *
  89. * @param array $variables
  90. * An associative array containing:
  91. * - item: An ImageItem object.
  92. * - item_attributes: An optional associative array of html attributes to be
  93. * placed in the img tag.
  94. * - image_style: An optional image style.
  95. * - url: An optional \Drupal\Core\Url object.
  96. */
  97. // function materiotheme_preprocess_image_formatter(&$vars){
  98. // if(isset($vars['url'])){
  99. // $system_path = $vars['url']->getInternalPath();
  100. // $vars['link_attributes'] = new Attribute(array(
  101. // 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path,
  102. // 'class' => array('ajax-link')
  103. // ));
  104. // // dpm($vars);
  105. // }
  106. // }
  107. // function materiotheme_preprocess_links__language_block(&$vars){
  108. // // dpm($vars);
  109. // // foreach ($vars['links'] as $lang_code => $link) {
  110. // // $vars['links'][$lang_code]['text'] = $lang_code;
  111. // // $vars['links'][$lang_code]['link']['#title'] = $lang_code;
  112. // // }
  113. // }