Skip to content

Commit

Permalink
Merge pull request #11868 from eileenmcnaughton/cust_url
Browse files Browse the repository at this point in the history
CRM-20922 fix support for passing custom date values via url
  • Loading branch information
eileenmcnaughton authored May 6, 2018
2 parents 8deedea + 31349d2 commit 518669f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
14 changes: 1 addition & 13 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -1724,19 +1724,7 @@ public static function extractGetParams(&$form, $type) {
}
}
elseif ($field['data_type'] == 'Date') {
if (!empty($value)) {
$time = NULL;
if (!empty($field['time_format'])) {
$time = CRM_Utils_Request::retrieve($fieldName .
'_time', 'String', $form, FALSE, NULL, 'GET');
}
list($value, $time) = CRM_Utils_Date::setDateDefaults($value .
' ' . $time);
if (!empty($field['time_format'])) {
$customValue[$fieldName . '_time'] = $time;
}
}
$valid = TRUE;
$valid = CRM_Utils_Rule::date($value);
}

if ($valid) {
Expand Down
43 changes: 43 additions & 0 deletions tests/phpunit/CRM/Core/BAO/CustomGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,47 @@ public function testGetGroupTitles() {
$this->customGroupDelete($customGroup['id']);
}

/**
* Test that passed dates are extracted from the url when processing custom data.
*/
public function testExtractGetParamsReturnsDates() {
// Create a custom group to contain the custom field.
$groupParams = array(
'title' => 'My Custom Group',
'name' => 'my_custom_group',
'extends' => 'Individual',
'is_active' => 1,
'collapse_display' => 1,
);
$customGroup = $this->customGroupCreate($groupParams);
$customGroupId = $customGroup['id'];

// Create teh custom field.
$fieldParams = array(
'custom_group_id' => $customGroupId,
'label' => 'My Custom Date Field',
'html_type' => 'Select Date',
'data_type' => 'Date',
'is_required' => 1,
'is_searchable' => 0,
'is_active' => 1,
'default_value' => '',
);
$customField = $this->customFieldCreate($fieldParams);
$customFieldId = $customField['id'];

// Create a form object. CRM_Core_BAO_CustomGroup::extractGetParams() will
// need this, along with the REQUEST_METHOD and controller too.
$form = new CRM_Contribute_Form_Contribution();
$_SERVER['REQUEST_METHOD'] = 'GET';
$form->controller = new CRM_Core_Controller();

// Set the value in $_GET, then extract query string params with
$fieldName = 'custom_' . $customFieldId;
$_GET[$fieldName] = '2017-06-13';
$extractedGetParams = CRM_Core_BAO_CustomGroup::extractGetParams($form, 'Individual');

$this->assertEquals($extractedGetParams[$fieldName], '2017-06-13');
}

}

0 comments on commit 518669f

Please sign in to comment.