Force jj/mm/aaaa on the ligne_comptable date field, regardless of browser locale
The native <input type="date"> 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 <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,22 @@ function figli_compta_ledger_form_alter(&$form, FormStateInterface $form_state,
|
|||||||
}
|
}
|
||||||
$form['#validate'][] = 'figli_compta_ledger_validate_repartition';
|
$form['#validate'][] = 'figli_compta_ledger_validate_repartition';
|
||||||
|
|
||||||
|
// The default date widget renders as a native <input type="date">,
|
||||||
|
// 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
|
// Every save must create a revision, unconditionally -- there's no
|
||||||
// legitimate reason to skip it for an accounting record, so don't let
|
// legitimate reason to skip it for an accounting record, so don't let
|
||||||
// anyone opt out. #access = FALSE (rather than just leaving the
|
// anyone opt out. #access = FALSE (rather than just leaving the
|
||||||
|
|||||||
Reference in New Issue
Block a user