Commit 6e8af268 authored by eileen's avatar eileen 🎱 Committed by GitHub

Merge pull request #9888 from eileenmcnaughton/cust_another

CRM-19490: Profile date fields don't respect localisation on the Cont…
parents ee876c95 8a6567d7
......@@ -5908,7 +5908,7 @@ AND displayRelType.is_active = 1
// This is a temporary routine for handling these fields while
// we figure out how to handled them based on metadata in
/// export and search builder. CRM-19815, CRM-19830.
if (isset($dao->$realField) && is_numeric($dao->$realField)) {
if (isset($dao->$realField) && is_numeric($dao->$realField) && isset($dao->$labelField)) {
$dao->$realField = $dao->$labelField;
}
}
......
......@@ -518,6 +518,9 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
);
$formattedField = CRM_Utils_Date::addDateMetadataToField($fieldMetaData, $formattedField);
if (in_array($name, array_keys(self::getNonUpgradedDateFields()))) {
$formattedField['is_legacy_date'] = 1;
}
//adding custom field property
if (substr($field->field_name, 0, 6) == 'custom' ||
......@@ -1905,6 +1908,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 )
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'address_options', TRUE, NULL, TRUE
);
$legacyHandledDateFields = self::getNonUpgradedDateFields();
if (substr($fieldName, 0, 14) === 'state_province') {
$form->addChainSelect($name, array('label' => $title, 'required' => $required));
......@@ -1967,15 +1971,8 @@ AND ( entity_id IS NULL OR entity_id <= 0 )
}
}
}
elseif (($fieldName === 'birth_date') || ($fieldName === 'deceased_date')) {
$form->addDate($name, $title, $required, array('formatType' => 'birth'));
}
elseif (in_array($fieldName, array(
'membership_start_date',
'membership_end_date',
'join_date',
))) {
$form->addDate($name, $title, $required, array('formatType' => 'activityDate'));
elseif (isset($legacyHandledDateFields[$fieldName])) {
$form->addDate($name, $title, $required, array('formatType' => $legacyHandledDateFields[$fieldName]));
}
elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
......@@ -2151,14 +2148,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 )
CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, $required, $search, $title);
}
}
elseif (in_array($fieldName, array(
'receive_date',
'receipt_date',
'thankyou_date',
'cancel_date',
))) {
$form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
}
elseif ($fieldName == 'send_receipt') {
$form->addElement('checkbox', $name, $title);
}
......@@ -2230,9 +2219,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 )
) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'
);
}
elseif ($fieldName == 'participant_register_date') {
$form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
}
elseif ($fieldName == 'activity_status_id') {
$form->add('select', $name, $title,
array(
......@@ -2247,9 +2233,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 )
) + CRM_Campaign_PseudoConstant::engagementLevel(), $required
);
}
elseif ($fieldName == 'activity_date_time') {
$form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime'));
}
elseif ($fieldName == 'participant_status') {
$cond = NULL;
if ($online == TRUE) {
......@@ -2347,6 +2330,30 @@ AND ( entity_id IS NULL OR entity_id <= 0 )
}
}
/**
* Get fields that have not been upgraded to use datepicker.
*
* Fields that use the old code have jcalendar in the tpl and
* the form uses a customised format. We are moving towards datepicker
* which among other things passes dates back and forth using a standardised
* format. Remove fields from here as they are tested and converted.
*/
static public function getNonUpgradedDateFields() {
return array(
'birth_date' => 'birth',
'deceased_date' => 'birth',
'membership_start_date' => 'activityDate',
'membership_end_date' => 'activityDate',
'join_date' => 'activityDate',
'receive_date' => 'activityDateTime',
'receipt_date' => 'activityDateTime',
'thankyou_date' => 'activityDateTime',
'cancel_date' => 'activityDateTime',
'participant_register_date' => 'activityDateTime',
'activity_date_time' => 'activityDateTime',
);
}
/**
* Set profile defaults.
*
......
......@@ -56,6 +56,10 @@ function smarty_modifier_crmDate($dateString, $dateFormat = NULL, $onlyTime = FA
$config = CRM_Core_Config::singleton();
$dateFormat = $config->dateformatTime;
}
// Handle possibility we only have a date function style date format.
if ($dateFormat && !stristr($dateFormat, '%')) {
return date($dateFormat, strtotime($dateString));
}
return CRM_Utils_Date::customFormat($dateString, $dateFormat);
}
......
......@@ -1775,20 +1775,22 @@ class CRM_Utils_Date {
public static function addDateMetadataToField($fieldMetaData, $field) {
if (isset($fieldMetaData['html'])) {
$field['html_type'] = $fieldMetaData['html']['type'];
if ($field['html_type'] === 'Select Date' && !isset($field['date_format'])) {
$dateAttributes = CRM_Core_SelectValues::date($fieldMetaData['html']['formatType'], NULL, NULL, NULL, 'Input');
$field['start_date_years'] = $dateAttributes['minYear'];
$field['end_date_years'] = $dateAttributes['maxYear'];
$field['date_format'] = $dateAttributes['format'];
$field['is_datetime_field'] = TRUE;
$field['time_format'] = $dateAttributes['time'];
$field['php_datetime_format'] = CRM_Utils_Date::getPhpDateFormatFromInputStyleDateFormat($field['date_format']);
if ($field['time_format']) {
$field['php_datetime_format'] .= ' H-i-s';
if ($field['html_type'] === 'Select Date') {
if (!isset($field['date_format'])) {
$dateAttributes = CRM_Core_SelectValues::date($fieldMetaData['html']['formatType'], NULL, NULL, NULL, 'Input');
$field['start_date_years'] = $dateAttributes['minYear'];
$field['end_date_years'] = $dateAttributes['maxYear'];
$field['date_format'] = $dateAttributes['format'];
$field['is_datetime_field'] = TRUE;
$field['time_format'] = $dateAttributes['time'];
$field['php_datetime_format'] = CRM_Utils_Date::getPhpDateFormatFromInputStyleDateFormat($field['date_format']);
if ($field['time_format']) {
$field['php_datetime_format'] .= ' H-i-s';
}
}
$field['datepicker']['extra'] = self::getDatePickerExtra($field);
$field['datepicker']['attributes'] = self::getDatePickerAttributes($field);
}
$field['datepicker']['extra'] = self::getDatePickerExtra($field);
$field['datepicker']['attributes'] = self::getDatePickerAttributes($field);
}
return $field;
}
......
......@@ -89,16 +89,17 @@
{include file="CRM/Profile/Form/GreetingType.tpl"}
{elseif ($profileFieldName eq 'group' && $form.group) || ($profileFieldName eq 'tag' && $form.tag)}
{include file="CRM/Contact/Form/Edit/TagsAndGroups.tpl" type=$profileFieldName title=null context="profile"}
{elseif ( $profileFieldName|substr:-5:5 eq '_date' ) AND
( $form.formName neq 'Confirm' ) AND
( $form.formName neq 'ThankYou' ) }
{include file="CRM/common/jcalendar.tpl" elementName=$profileFieldName}
{elseif ( $profileFieldName|substr:-5:5 eq '_date' ) }
{elseif $field.is_datetime_field && $action & 4}
{assign var="date_value" value=$form.$profileFieldName.value}
<span class="crm-frozen-field">
{$date_value|date_format:"%Y-%m-%d"|crmDate:$config->dateformatshortdate}
<input type="hidden" name="{$form.$profileFieldName.name}" value="{$form.$profileFieldName.value}" id="{$form.$profileFieldName.name}">
</span>
{$date_value|date_format:"%Y-%m-%d"|crmDate:$config->dateformatshortdate}
<input type="hidden"
name="{$form.$profileFieldName.name}"
value="{$form.$profileFieldName.value}" id="{$form.$profileFieldName.name}"
>
</span>
{elseif $field.is_legacy_date}
{include file="CRM/common/jcalendar.tpl" elementName=$profileFieldName}
{elseif $profileFieldName|substr:0:5 eq 'phone'}
{assign var="phone_ext_field" value=$profileFieldName|replace:'phone':'phone_ext'}
{if $prefix}{$form.$prefix.$profileFieldName.html}{else}{$form.$profileFieldName.html}{/if}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment