materiotheme.theme 3.5 KB

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