reha.theme 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. use Drupal\Core\Url;
  3. use Drupal\Core\Link;
  4. use Drupal\Core\Render\Markup;
  5. use Drupal\Component\Utility\Html;
  6. /**
  7. * @file
  8. * Functions to support theming in the reha theme.
  9. */
  10. /**
  11. * Implements hook_preprocess_HOOK() for html.html.twig.
  12. */
  13. function reha_preprocess_html(&$variables) {
  14. $node = \Drupal::routeMatch()->getParameter('node');
  15. if ($node){
  16. $variables['attributes']['class'][] = 'node-type-' . $node->bundle();
  17. $variables['attributes']['class'][] = 'node-id-' . $node->id();
  18. }
  19. }
  20. /**
  21. * Implements hook_preprocess_HOOK() for node.html.twig.
  22. */
  23. function reha_preprocess_node(&$variables) {
  24. $node = &$variables['node'];
  25. $variables['attributes']['class'][] = 'node-type-' . $node->gettype();
  26. if ($node->getType() == 'site' || $node->getType() == 'ressource' || $node->getType() == 'actualite') {
  27. $fields_to_exclude = [
  28. 'field_image', // Remplacez par le nom machine exact de votre champ image
  29. ];
  30. $filtered_content = [];
  31. $image_field_content = '';
  32. $body_field_content = '';
  33. $files_field_content = '';
  34. $liens_field_content = '';
  35. foreach ($variables['content'] as $field_name => $field_content) {
  36. if ($field_name == 'body') {
  37. $body_field_content = $field_content;
  38. } elseif ($field_name == 'field_fichiers') {
  39. $files_field_content = $field_content;
  40. } elseif ($field_name == 'field_liens') {
  41. $liens_field_content = $field_content;
  42. } elseif (!in_array($field_name, $fields_to_exclude)) {
  43. $filtered_content[$field_name] = $field_content;
  44. } else {
  45. $image_field_content = $field_content;
  46. }
  47. }
  48. $variables['filtered_content'] = $filtered_content;
  49. $variables['image_field_content'] = $image_field_content;
  50. $variables['body_field_content'] = $body_field_content;
  51. $variables['files_field_content'] = $files_field_content;
  52. $variables['liens_field_content'] = $liens_field_content;
  53. }
  54. }
  55. function reha_preprocess_block(&$variables) {
  56. // Conserver les IDs existants et générer un ID unique uniquement si aucun ID n'est présent
  57. if (empty($variables['attributes']['id'])) {
  58. $block_id = 'block-' . uniqid();
  59. $variables['attributes']['id'] = $block_id;
  60. }
  61. if ($variables['plugin_id'] === "user_login_block") {
  62. $url = new Url('user.register', [], ['query' => ['destination' => '/node/add/operation']]);
  63. $link = new Link('proposer une opération', $url);
  64. $variables['content']['reha'] = array(
  65. '#theme' => 'item_list',
  66. '#items' => [
  67. 'operations' => [
  68. "add_operation" => $link->toRenderable(),
  69. "description" => [
  70. "#markup" => Markup::create("<p>Créer un compte pour charger une opération</p>")
  71. ]
  72. ]
  73. ]
  74. );
  75. }
  76. if ($variables['plugin_id'] === "page_title_block") {
  77. if (\Drupal::routeMatch()->getRouteName() === 'node.add') {
  78. $node_type = \Drupal::routeMatch()->getParameter('node_type');
  79. if ($node_type->id() === 'operation') {
  80. $variables['content'] = [
  81. '#type' => 'page_title',
  82. '#title' => 'Proposer une opération'
  83. ];
  84. }
  85. }
  86. }
  87. }