From 463a7f343ccd007b97573c9b243b8ac13d7bb5e9 Mon Sep 17 00:00:00 2001 From: bach Date: Sun, 6 Sep 2026 18:03:18 +0200 Subject: [PATCH] Force jj/mm/aaaa on the ligne_comptable date field, regardless of browser locale The native widget's displayed digit order follows the browser's own locale, not Drupal's site language -- an English- locale browser was showing 07/26/2024. Switches the date sub-element to 'text' with an explicit PHP date format so Drupal parses/displays it consistently for everyone. Verified end-to-end (not just cosmetically): submitted 05/03/2024 through the real add form and confirmed it stored as 2024-03-05 (5 March), not 2024-05-03 -- genuinely parsed as day/month, not silently reinterpreted as month/day. Co-Authored-By: Claude Sonnet 5 --- .../figli_compta_ledger.module | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module b/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module index 092e6f6..b5b7354 100644 --- a/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module +++ b/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module @@ -37,6 +37,22 @@ function figli_compta_ledger_form_alter(&$form, FormStateInterface $form_state, } $form['#validate'][] = 'figli_compta_ledger_validate_repartition'; + // The default date widget renders as a native , + // whose displayed digit order (07/26/2024 vs 26/07/2024) follows the + // browser's own locale setting -- not anything Drupal or this site's + // language controls, so an English-locale browser shows the American + // mm/dd/yyyy order no matter what. Switching the date sub-element from + // 'date' (native picker) to 'text' with an explicit PHP date format + // makes Drupal itself own the display/parsing, so it's the same + // jj/mm/aaaa for everyone regardless of browser locale. Trade-off: + // loses the native calendar picker (Drupal core ships no JS date- + // picker to pair with the text variant) -- acceptable here, dates are + // typically typed directly for this kind of data entry. + if (isset($form['field_date_ligne']['widget'][0]['value'])) { + $form['field_date_ligne']['widget'][0]['value']['#date_date_element'] = 'text'; + $form['field_date_ligne']['widget'][0]['value']['#date_date_format'] = 'd/m/Y'; + } + // Every save must create a revision, unconditionally -- there's no // legitimate reason to skip it for an accounting record, so don't let // anyone opt out. #access = FALSE (rather than just leaving the