reha.theme 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. use Drupal\Core\Url;
  3. use Drupal\Core\Link;
  4. use Drupal\Core\Render\Markup;
  5. /**
  6. * @file
  7. * Functions to support theming in the reha theme.
  8. */
  9. /**
  10. * Implements hook_preprocess_HOOK() for html.html.twig.
  11. */
  12. function reha_preprocess_html(&$variables) {
  13. $node = \Drupal::routeMatch()->getParameter('node');
  14. if ($node){
  15. $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
  16. $variables['attributes']['class'][] = 'node-id-' . $node->id();
  17. }
  18. }
  19. /**
  20. * Implements hook_preprocess_HOOK() for page.html.twig.
  21. */
  22. function reha_preprocess_page(&$variables) {
  23. }
  24. /**
  25. * Implements hook_preprocess_HOOK() for node.html.twig.
  26. */
  27. function reha_preprocess_node(&$variables) {
  28. $node = &$variables['node'];
  29. $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  30. }
  31. /**
  32. * Prepares variables for block templates.
  33. *
  34. * Default template: block.html.twig.
  35. *
  36. * Prepares the values passed to the theme_block function to be passed
  37. * into a pluggable template engine. Uses block properties to generate a
  38. * series of template file suggestions. If none are found, the default
  39. * block.html.twig is used.
  40. *
  41. * Most themes use their own copy of block.html.twig. The default is located
  42. * inside "core/modules/block/templates/block.html.twig". Look in there for the
  43. * full list of available variables.
  44. *
  45. * @param array $variables
  46. * An associative array containing:
  47. * - elements: An associative array containing the properties of the element.
  48. * Properties used: #block, #configuration, #children, #plugin_id.
  49. */
  50. //https://www.hashbangcode.com/article/drupal-9-programmatically-creating-and-using-urls-and-links
  51. function reha_preprocess_block(&$variables) {
  52. if ($variables['plugin_id'] === "user_login_block") {
  53. $url = new Url('user.register', [], ['query' => ['destination' => '/node/add/operation']]);
  54. $link = new Link('proposer une opération', $url);
  55. $variables['content']['reha'] = array(
  56. '#theme' => 'item_list',
  57. '#items' => [
  58. 'operations' => [
  59. "add_operation" => $link->toRenderable(),
  60. "description" => [
  61. "#markup" => Markup::create("<p>Créer un compte pour charger une opération</p>")
  62. ]
  63. ]
  64. ]
  65. );
  66. }
  67. if ($variables['plugin_id'] === "page_title_block") {
  68. if (\Drupal::routeMatch()->getRouteName() === 'node.add') {
  69. $node_type = \Drupal::routeMatch()->getParameter('node_type');
  70. if ($node_type->id() === 'operation') {
  71. $variables['content'] = [
  72. '#type' => 'page_title',
  73. '#title' => 'Proposer une opération'
  74. ];
  75. }
  76. }
  77. }
  78. }