reha.theme 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if ($variables['node']->getType() == 'site') {
  31. $fields_to_exclude = [
  32. 'field--name-field-image',
  33. ];
  34. $filtered_content = [];
  35. $image_field_content = '';
  36. foreach ($variables['content'] as $field_name => $field_content) {
  37. if (!in_array($field_name, $fields_to_exclude)) {
  38. $filtered_content[$field_name] = $field_content;
  39. } else {
  40. $image_field_content = $field_content;
  41. }
  42. }
  43. $variables['filtered_content'] = $filtered_content;
  44. $variables['image_field_content'] = $image_field_content;
  45. }
  46. }
  47. function reha_preprocess_block(&$variables) {
  48. if ($variables['plugin_id'] === "user_login_block") {
  49. $url = new Url('user.register', [], ['query' => ['destination' => '/node/add/operation']]);
  50. $link = new Link('proposer une opération', $url);
  51. $variables['content']['reha'] = array(
  52. '#theme' => 'item_list',
  53. '#items' => [
  54. 'operations' => [
  55. "add_operation" => $link->toRenderable(),
  56. "description" => [
  57. "#markup" => Markup::create("<p>Créer un compte pour charger une opération</p>")
  58. ]
  59. ]
  60. ]
  61. );
  62. }
  63. if ($variables['plugin_id'] === "page_title_block") {
  64. if (\Drupal::routeMatch()->getRouteName() === 'node.add') {
  65. $node_type = \Drupal::routeMatch()->getParameter('node_type');
  66. if ($node_type->id() === 'operation') {
  67. $variables['content'] = [
  68. '#type' => 'page_title',
  69. '#title' => 'Proposer une opération'
  70. ];
  71. }
  72. }
  73. }
  74. }