edlp_home.module 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. # @Author: Bachir Soussi Chiadmi <bach>
  3. # @Date: 13-12-2017
  4. # @Email: bachir@figureslibres.io
  5. # @Filename: edlp_home.module
  6. # @Last modified by: bach
  7. # @Last modified time: 20-12-2017
  8. # @License: GPL-V3
  9. /**
  10. * Implements hook_theme().
  11. */
  12. function edlp_home_theme($existing, $type, $theme, $path) {
  13. // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
  14. return array(
  15. 'edlp_home' => array(
  16. // 'render element' => '',
  17. 'file' => 'includes/edlp_home.inc',
  18. 'variables' => array(
  19. // 'presentation_node' => NULL,
  20. // 'last_fil_node' => NULL,
  21. // 'last_production_node' => NULL,
  22. 'promoted_statics' => array(),
  23. 'promoted_prods' => array(),
  24. 'lastdocs_items' => NULL,
  25. 'agenda_items' => NULL,
  26. // 'entrees_items' => NULL,
  27. 'collection_link' => NULL,
  28. 'production_link' => NULL,
  29. 'agenda_link' => NULL,
  30. ),
  31. ),
  32. );
  33. }
  34. /**
  35. * Implements hook_theme_suggestions_HOOK().
  36. */
  37. function edlp_home_theme_suggestions_edlp_home_alter(array &$suggestions, array $variables) {
  38. $is_mobile_domain = false;
  39. // get domains from domain module
  40. $domain_storage = \Drupal::entityTypeManager()->getStorage('domain');
  41. $mobile_domain_id = 'm_encyclopediedelaparole_org';
  42. // $mobile_domain = $domain_storage->load('m_encyclopediedelaparole_org');
  43. global $base_root;
  44. // get the current hostname (domain)
  45. $current_hostname = preg_replace('/http:\/\/|https:\/\//i', '', $base_root);
  46. // get the current domain
  47. $current_domain = $domain_storage->loadByHostname($current_hostname);
  48. if($current_domain){
  49. // we are in a main domain
  50. // $is_mobile_domain = ($current_domain->id() == $mobile_domain_id);
  51. $current_domain_id = $current_domain->id();
  52. }else{
  53. // we are not in a main domain, so we look for an alias
  54. $domain_alias_storage = \Drupal::entityTypeManager()->getStorage('domain_alias');
  55. $alias = $domain_alias_storage->loadByHostname($current_hostname);
  56. // dpm($alias, '$alias');
  57. $current_domain_id = $alias->getDomainId();
  58. }
  59. $is_mobile_domain = $current_domain_id == $mobile_domain_id;
  60. if($is_mobile_domain){
  61. array_unshift($suggestions, 'edlp_home__mobile');
  62. }
  63. }