Skip to content

Commit

Permalink
Handle date field conversion, don't call normalize twice
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 4, 2019
1 parent e897889 commit e1be97f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion CRM/Contact/Form/Search/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ public function setDefaultValues() {
'privacy_toggle' => 1,
'operator' => 'AND',
));
$this->normalizeDefaultValues($defaults);

if ($this->_context === 'amtg') {
$defaults['task'] = CRM_Contact_Task::GROUP_ADD;
Expand Down
23 changes: 23 additions & 0 deletions CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,27 @@ protected function loadFormValues() {
}
}

/**
* Do form value conversions based on form metadata.
*/
public function convertFormValues() {
$metadata = $this->getSearchFieldMetadata();
foreach ($metadata as $fields) {
foreach ($fields as $field => $spec) {
if ($spec['type'] == CRM_Utils_Type::T_DATE) {
if (isset($this->_formValues[$field . '_low'])) {
if (date('Y-m-d H:i:s', strtotime($this->_formValues[$field . '_low'])) !== $this->_formValues[$field . '_low']) {
$this->_formValues[$field . '_low'] = date('Y-m-d H:i:s', strtotime(CRM_Utils_Date::processDate($this->_formValues[$field . '_low'])));
}
}
if (isset($this->_formValues[$field . '_high'])) {
if (date('Y-m-d H:i:s', strtotime($this->_formValues[$field . '_low'])) !== $this->_formValues[$field . '_high']) {
$this->_formValues[$field . '_high'] = date('Y-m-d H:i:s', strtotime(CRM_Utils_Date::processDate($this->_formValues[$field . '_high'])));
}
}
}
}
}
}

}
2 changes: 2 additions & 0 deletions CRM/Grant/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,11 @@ public static function getTemplateHandlableSearchFields() {
*/
public static function buildSearchForm(&$form) {


$grantType = CRM_Core_OptionGroup::values('grant_type');
$form->addSearchFieldMetadata(['Grant' => self::getSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();
$form->convertFormValues();
$form->assign('grantSearchFields', self::getTemplateHandlableSearchFields());
$form->add('select', 'grant_type_id', ts('Grant Type'), $grantType, FALSE,
array('id' => 'grant_type_id', 'multiple' => 'multiple', 'class' => 'crm-select2')
Expand Down

0 comments on commit e1be97f

Please sign in to comment.