From d975405623e7809d11bbdea3a7cf8fb4833cf67d Mon Sep 17 00:00:00 2001 From: Civiware Solutions Date: Sun, 31 Mar 2019 04:43:01 +0530 Subject: [PATCH] Fixed set default for date fields --- CRM/EntityTemplates/Utils.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CRM/EntityTemplates/Utils.php b/CRM/EntityTemplates/Utils.php index f36ac0b..c62b3e3 100644 --- a/CRM/EntityTemplates/Utils.php +++ b/CRM/EntityTemplates/Utils.php @@ -82,13 +82,16 @@ class CRM_EntityTemplates_Utils { if ($form->_entityTemplateId) { $formValues = CRM_EntityTemplates_BAO_EntityTemplates::getFormValues($form->_entityTemplateId); $formValues['entity_template_id'] = $form->_entityTemplateId; + + self::formatDateParams($formValues, $form->_elements); $form->setDefaults($formValues); + CRM_Core_Resources::singleton()->addScript(" CRM.$(function($) { $(document).ajaxSend(function(event, jqxhr, settings) { if (settings.url .indexOf('civicrm/custom') != -1) { settings.url = settings.url + '&templateId={$form->_entityTemplateId}'; - } + } }); })", 10, @@ -143,4 +146,24 @@ class CRM_EntityTemplates_Utils { } } + /** + * Format Date field values in params. + * + * @param array $params + * @param object $elements + */ + public static function formatDateParams(&$params, $elements) { + foreach ($elements as $element) { + if (!empty($element->_attributes) && array_key_exists( + 'data-crm-datepicker', + $element->_attributes + )) { + $name = $element->_attributes['name']; + if (!CRM_Utils_System::isNull($params[$name])) { + $params[$name] = date('Y-m-d H:i:s', strtotime($params[$name])); + } + } + } + } + }