edlptheme.theme 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support theming in the edlp theme.
  5. */
  6. use Drupal\Core\Url;
  7. use Drupal\Core\Form\FormStateInterface;
  8. use Drupal\Core\Template\Attribute;
  9. // function edlptheme_preprocess_input(&$vars){
  10. // dsm($vars, 'vars');
  11. // $vars['attributes']['placeholder'] = "salut";
  12. // }
  13. function edlptheme_preprocess_node(&$vars){
  14. $node = $vars['elements']['#node'];
  15. $options = ['absolute' => TRUE];
  16. $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options);
  17. $system_path = $url->getInternalPath();
  18. $vars['link_attributes'] = new Attribute(array(
  19. 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path
  20. ));
  21. }
  22. /**
  23. * Implements hook_form_alter
  24. */
  25. function edlptheme_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  26. // dpm($form_id, 'form_id');
  27. // dpm($form, 'form');
  28. $form['name']['#attributes']['placeholder'] = (string) $form['name']['#title'];
  29. unset($form['name']['#title']);
  30. $form['pass']['#attributes']['placeholder'] = (string) $form['pass']['#title'];
  31. unset($form['pass']['#title']);
  32. }
  33. function edlptheme_preprocess_edlp_productions(&$vars){
  34. foreach($vars['nodes'] as &$node){
  35. switch($node['vm']){
  36. case "image_2_columns":
  37. $cols = 4;
  38. break;
  39. case "image_1_columns":
  40. $cols = 2;
  41. break;
  42. case "text_1_column":
  43. $cols = 2;
  44. break;
  45. };
  46. $node['cols'] = $cols;
  47. }
  48. // dpm($vars);
  49. }
  50. function edlptheme_preprocess_node__player_cartel(&$vars){
  51. // dpm($vars);
  52. // if transcript not empty
  53. $url = Url::fromRoute('entity.node.canonical', ['node'=>$vars['node']->id()], array(
  54. 'attributes' => array(
  55. 'class' => ['link-transcript', 'ajax-link'],
  56. 'viewmode'=>'transcript'
  57. )
  58. ));
  59. $vars['link_transcript'] = array(
  60. '#title' => t("Lire le text."),
  61. '#type' => 'link',
  62. '#url' => $url,
  63. '#options'=>array(
  64. 'attributes' => array(
  65. 'data-drupal-link-system-path' => $url->getInternalPath()
  66. )
  67. )
  68. );
  69. // if article not empty
  70. $url = Url::fromRoute('entity.node.canonical', ['node'=>$vars['node']->id()], array(
  71. 'attributes' => array(
  72. 'class' => ['link-article', 'ajax-link'],
  73. 'viewmode'=>'article'
  74. )
  75. ));
  76. $vars['link_article'] = array(
  77. '#title' => t("Lire l'article."),
  78. '#type' => 'link',
  79. '#url' => $url,
  80. '#options' => array(
  81. 'attributes'=>array(
  82. 'data-drupal-link-system-path' => $url->getInternalPath()
  83. )
  84. )
  85. );
  86. // if article or transcript
  87. $vars['col_left'] = true;
  88. // if
  89. $vars['col_right'] = true;
  90. }