From 657cae7c3cc87ca9424df44c21a26c7e6b5ed715 Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Wed, 29 Apr 2015 11:40:25 -0400 Subject: [PATCH] CRM-14588: Format date fields in contribution confirm page. --- CRM/Core/Form/Renderer.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index f67c2e332f..3c1117578b 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -120,6 +120,10 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { if ($element->getAttribute('data-api-entity') && $element->getAttribute('data-entity-value')) { $this->renderFrozenEntityRef($el, $element); } + elseif ($element->getAttribute('type') == 'text' && ! empty($element->getAttribute('format'))) { + $this->renderFrozenDate($el, $element); + } + $el['html'] = '' . $el['html'] . ''; } // Active form elements @@ -260,6 +264,24 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { $el['html'] = implode('; ', $display) . ''; } + /** + * Render a date field as text. + * + * @param array $el + * @param HTML_QuickForm_element $field + */ + public function renderFrozenDate(&$el, $field) { + $format = $field->getAttribute('format'); + $map = CRM_Core_SelectValues::datePluginToPHPFormats($format); + + if (isset($map[$format])) { + $format = $map[$format]; + } + + $date = DateTime::createFromFormat('d/m/Y', $field->getValue()); + $el['html'] = $date->format($format) . ''; + } + /** * Pre-fill contact name for a custom field of type ContactReference * -- 2.25.1