ouatminimal.theme 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support theming in the Seven theme.
  5. */
  6. use Drupal\breakpoint\Breakpoint;
  7. use Drupal\Core\Form\FormStateInterface;
  8. use \Drupal\Core\Url;
  9. use Drupal\Core\Render\Markup;
  10. use function Psy\debug;
  11. /**
  12. * Implements hook_preprocess_HOOK() for HTML document templates.
  13. */
  14. // function ouatminimal_preprocess_html(&$variables) {
  15. // // If on a node add or edit page, add a node-layout class.
  16. // $path_args = explode('/', \Drupal::request()->getPathInfo());
  17. // if ($suggestions = theme_get_suggestions($path_args, 'page', '-')) {
  18. // foreach ($suggestions as $suggestion) {
  19. // // dsm($suggestion);
  20. // preg_match('/taxonomy-manage-[^-]+-add$/', $suggestion, $matches);
  21. // // ksm($matches);
  22. // if ($suggestion === 'page--taxonomy-term-edit' || isset($matches)) {
  23. // $variables['attributes']['class'][] = 'node-form-layout';
  24. // }
  25. // }
  26. // }
  27. // }
  28. // function ouatminimal_form_alter(&$form, FormStateInterface $form_state, $form_id){
  29. // // dsm($form_id);
  30. // // create a colomuned term form (not working yet)
  31. // if(in_array($form_id, ['taxonomy_term_company_form', 'taxonomy_term_showroom_form'])){
  32. // // ksm($form);
  33. // $form['#theme'] = ['term_edit_form'];
  34. // $form['#attached']['library'][] = 'seven/node-form';
  35. //
  36. // $form['advanced']['#type'] = 'container';
  37. // $form['meta']['#type'] = 'container';
  38. // $form['meta']['#access'] = TRUE;
  39. // $form['meta']['changed']['#wrapper_attributes']['class'][] = 'container-inline';
  40. // $form['meta']['author']['#wrapper_attributes']['class'][] = 'container-inline';
  41. //
  42. // $form['revision_information']['#type'] = 'container';
  43. // $form['revision_information']['#group'] = 'meta';
  44. // }
  45. // }
  46. /**
  47. * Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
  48. *
  49. * Changes vertical tabs to container.
  50. */
  51. function ouatminimal_form_node_form_alter(&$form, FormStateInterface $form_state) {
  52. $form['#theme'] = ['node_edit_form'];
  53. $form['#attached']['library'][] = 'seven/node-form';
  54. if ($form["#form_id"] != 'node_static_edit_form') {
  55. $form['advanced']['#type'] = 'container';
  56. // $form['advanced']['#access'] = true;
  57. $form['meta']['#type'] = 'container';
  58. $form['meta']['#access'] = TRUE;
  59. $form['meta']['changed']['#wrapper_attributes']['class'][] = 'container-inline';
  60. $form['meta']['author']['#wrapper_attributes']['class'][] = 'container-inline';
  61. $form['revision_information']['#type'] = 'container';
  62. $form['revision_information']['#group'] = 'meta';
  63. // $form['author']['#group']['group_admin'];
  64. }
  65. }
  66. // https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme_suggestions_HOOK_alter/10
  67. function ouatminimal_theme_suggestions_node_edit_form_alter(array &$suggestions, array $variables) {
  68. if ($node = \Drupal::routeMatch()->getParameter('node')){
  69. $nid = $node->id();
  70. $type = $node->getType();
  71. $suggestions[] = 'node_edit_form__node_' . $type;
  72. }
  73. }
  74. // https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme_suggestions_HOOK_alter/10
  75. function ouatminimal_theme_suggestions_field_multiple_value_form_alter(array &$suggestions, array $variables) {
  76. if ($node = \Drupal::routeMatch()->getParameter('node')){
  77. $nid = $node->id();
  78. $type = $node->getType();
  79. $suggestions[] = 'field_multiple_value_form__' . $variables['element']['#field_name'];
  80. $suggestions[] = 'field_multiple_value_form__node_' . $type;
  81. $suggestions[] = 'field_multiple_value_form__' . $variables['element']['#field_name'] . '__node_' . $type;
  82. }
  83. }
  84. // field-multiple-value-form--field-entite--node-concernement
  85. function ouatminimal_preprocess_field_multiple_value_form__field_entite__node_concernement(&$variables) {
  86. // $element = $variables['element'];
  87. $attributes = $variables['attributes'];
  88. $variables['#attached']['library'][] = 'ouatminimal/boussole';
  89. }
  90. // template_preprocess_field_multiple_value_form
  91. // function ouatminimal_preprocess_field_multiple_value_form(&$variables) {
  92. // $element = $variables['element'];
  93. // $attributes = $variables['attributes'];
  94. // if($attributes['data-drupal-selector'] === 'edit-field-entite' ){
  95. // $t="t";
  96. // }
  97. // }
  98. function ouatminimal_preprocess_toolbar(&$variables) {
  99. unset($variables['tabs']['home']['link']['#options']['attributes']['data-toolbar-escape-admin']);
  100. unset($variables['tabs']['home']['link']['#attributes']['data-toolbar-escape-admin']);
  101. unset($variables['tabs']['home']['link']['#markup']);
  102. unset($variables['tabs']['home']['link']['#children']);
  103. $uri = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
  104. $variables['tabs']['home']['link']['#url'] = Url::fromUri($uri);
  105. }
  106. function ouatminimal_preprocess_form_element(&$variables) {
  107. $element = $variables['element'];
  108. if(isset($variables['description_display'])){
  109. $variables['description_display']="before";
  110. }
  111. }
  112. /**
  113. * Prepares variables for text format wrapper templates.
  114. *
  115. * Default template: text-format-wrapper.html.twig.
  116. *
  117. * @param array $variables
  118. * An associative array containing:
  119. * - attributes: An associative array containing properties of the element.
  120. */
  121. // function ouatminimal_preprocess_text_format_wrapper(&$variables) {
  122. // $t="t";
  123. // // $children = $variables['children'];
  124. // }
  125. function ouatminimal_preprocess_textarea(&$variables) {
  126. $element = $variables['element'];
  127. unset($variables['element']['#cols']);
  128. $variables['attributes']->removeAttribute('cols');
  129. // $variables['attributes']->setAttribute('cols', 40);
  130. }
  131. // function ouatminimal_preprocess_node_edit_form__node_concernement(&$variables) {
  132. // // $variables['form']['advanced']['#group'] = "group_admin";
  133. // // $ph = $variables['form']['title']['widget'][0]['value']['#placeholder'];
  134. // // $variables['form']['title']['widget']['#description'] = $ph;
  135. // // $variables['form']['title']['widget'][0]['#description'] = $ph;
  136. // // $variables['form']['title']['widget'][0]['value']['#description'] = $ph;
  137. // // $variables['form']['title']['widget']['#title'] = $ph;
  138. // // $variables['form']['title']['widget'][0]['#title'] = $ph;
  139. // // $variables['form']['title']['widget'][0]['value']['#title'] = $ph;
  140. // // $variables['form']['title']['widget'][0]['value']['#placeholder'] = "";
  141. // }
  142. function ouatminimal_preprocess_input(&$variables) {
  143. $element = &$variables['element'];
  144. if ($element['#type'] === "submit") {
  145. // edit-field-entite-0-subform-field-entite-actions-ief-add
  146. $name = $element['#name'];
  147. // rename entité reference in paragraphe "add node" to "editer entité"
  148. if (preg_match('/^ief-field_entite-\d+-subform-field_entite-form-add$/', $name)) {
  149. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Editer l'entité";
  150. }
  151. // ief-add-submit-field_entite-15-subform-field_entite-form
  152. if (preg_match('/^ief-add-submit-field_entite-\d+-subform-field_entite-form$/', $name)) {
  153. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Créer l'entité";
  154. }
  155. // ief-edit-submit-field_entite-14-subform-field_entite-form-0
  156. if (preg_match('/^ief-edit-submit-field_entite-\d+-subform-field_entite-form-\d+$/', $name)) {
  157. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Enregistrer l'entité";
  158. }
  159. // rename remove (paragraphe) to "supprimer"
  160. if (preg_match('/field_entite_\d+_remove/', $name)) {
  161. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Supprimer";
  162. }
  163. // hide remove node ref submit
  164. if (preg_match('/^ief-field_entite-\d+-subform-field_entite-form-entity-remove-\d+$/', $name)) {
  165. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "test";
  166. $variables['attributes']['class'][] = 'ief-submit-remove';
  167. }
  168. // puissance d'agir
  169. // rename ajouter besoin
  170. // edit-field-besoin-actions-ief-add--auhryC0X7yE
  171. if (preg_match('/^ief-field_besoin-form-add$/', $name)) {
  172. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Ajouter un Besoin";
  173. }
  174. // ief-edit-submit-field_besoin-form-0
  175. if (preg_match('/^ief-edit-submit-field_besoin-form-\d$/', $name)) {
  176. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Mise à jour du besoin";
  177. }
  178. // ief-add-submit-field_besoin-form
  179. if (preg_match('/^ief-add-submit-field_besoin-form$/', $name)) {
  180. $element['#value'] = $element['#attributes']['value'] = $variables['attributes']['value'] = "Créer le besoin";
  181. }
  182. }
  183. if ($element['#type'] === "text" || $element['#type'] === "url") {
  184. unset($variables['element']['#size']);
  185. // $variables['attributes']->removeAttribute('size');
  186. // $variables['attributes']->setAttribute('cols', 40);
  187. }
  188. }