edlp_ajax.module 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. # @Author: Bachir Soussi Chiadmi <bach>
  3. # @Email: bachir@figureslibres.io
  4. # @Filename: edlp_ajax.module
  5. # @License: GPL-V3
  6. /**
  7. * Implements hook_theme().
  8. */
  9. function edlp_ajax_theme($existing, $type, $theme, $path) {
  10. // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
  11. return array(
  12. 'edlp_ajax' => array(
  13. 'file' => 'includes/edlp_ajax.inc',
  14. 'variables' => array(
  15. 'entity_type' => 'node',
  16. 'entity' => NULL,
  17. 'view_mode' => 'default'
  18. ),
  19. ),
  20. );
  21. }
  22. /**
  23. * Implements hook_theme_suggestions_HOOK().
  24. */
  25. function edlp_ajax_theme_suggestions_edlp_ajax(array $vars) {
  26. // dpm($vars);
  27. $suggestions = [];
  28. // $node = $variables['elements']['#node'];
  29. $sanitized_view_mode = strtr($vars['view_mode'], '.', '_');
  30. //
  31. $suggestions[] = 'edlp_ajax__' . $vars['entity_type'];
  32. $suggestions[] = 'edlp_ajax__' . $vars['entity_type'] . '__' . $sanitized_view_mode;
  33. // $suggestions[] = 'node__' . $node->bundle() . '__' . $sanitized_view_mode;
  34. $suggestions[] = 'edlp_ajax__' . $vars['entity_type'] . '__' . $vars['entity']->id();
  35. $suggestions[] = 'edlp_ajax__' . $vars['entity_type'] . '__' . $vars['entity']->id() . '__' . $sanitized_view_mode;
  36. return $suggestions;
  37. }