-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#1405 Strip any spaces from Option Group name parameter and r… #15937
Conversation
(Standard links)
|
5bd1bff
to
5fbf3d3
Compare
Fantastic, thanks @seamuslee001 will test and report back here. |
Fixes this issue, https://lab.civicrm.org/dev/core/issues/1405 @seamuslee001 thanks also for including the Agileware Ref made it much easier to find the related issues. Legend! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @seamuslee001 - I think the main thing here is that the option group name should be lower case, not preserve mixed case from the title.
As a side comment, I really don't understand why CRM_Utils_String::titleToVar doesn't do the case conversion as that would save work here and possibly elsewhere too.
CRM/Admin/Form/OptionGroup.php
Outdated
public static function formRule($fields, $files, $self) { | ||
$errors = []; | ||
if ($self->_id) { | ||
$name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGrou', $self->_id, 'name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here.
Should be:
$name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $self->_id, 'name');
CRM/Core/BAO/OptionGroup.php
Outdated
@@ -76,6 +76,12 @@ public static function add(&$params, $ids = []) { | |||
CRM_Core_Error::deprecatedFunctionWarning('no $ids array'); | |||
$params['id'] = $ids['optionGroup']; | |||
} | |||
if (empty($params['name']) && empty($params['id'])) { | |||
$params['name'] = CRM_Utils_String::titleToVar($params['title']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a strtolower here, otherwise Option Group Title: "Didgeridoo Kakapo" is saved as Option Group Name: "Didgeridoo_Kakapo" but should be "didgeridoo_kakapo"
$params['name'] = CRM_Utils_String::titleToVar(strtolower($params['title']));
CRM/Core/BAO/OptionGroup.php
Outdated
$params['name'] = CRM_Utils_String::titleToVar($params['title']); | ||
} | ||
elseif (!empty($params['name']) && strpos($params['name'], ' ')) { | ||
$params['name'] = CRM_Utils_String::titleToVar($params['name']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also convert to lowercase for any existing mixed case Option Group Names.
$params['name'] = CRM_Utils_String::titleToVar(strtolower($params['name']));
CRM/Admin/Form/OptionGroup.php
Outdated
$name = CRM_Utils_String::titleToVar(strtolower($fields['title'])); | ||
} | ||
if (!CRM_Core_DAO::objectExists($name, 'CRM_Core_DAO_OptionGroup', $self->_id)) { | ||
$errors['title'] = ts('Option Group name already exists in the database. Option Group Names need to be unique'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the name in the error message so that user knows what value is conflicting, otherwise it's not clear. Shorter message too.
$errors['title'] = ts('Option Group name: ' . $name .' already exists. Option Group Names need to be unique');
foreach ($optionGroups as $optionGroup) { | ||
$name = trim($optionGroup['name']); | ||
if (strpos($name, ' ') !== FALSE) { | ||
$fixedName = CRM_Utils_String::titleToVar($name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert to lowercase here as well during the upgrade.
$fixedName = CRM_Utils_String::titleToVar(strtolower($name));
Probably should at least log what option group names have been changed so that at least CiviCRM developers are forewarned after the upgrade that potentially any custom integration referring to the option group by name will now be broken. Just a suggestion.
*/ | ||
public function testFixOptionGroupName() { | ||
$name = 'This is a test Name'; | ||
$fixedName = CRM_Utils_String::titleToVar($name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a strtolower here too.
} | ||
elseif (!empty($params['name']) && strpos($params['name'], ' ')) { | ||
$params['name'] = CRM_Utils_String::titleToVar($params['name']); | ||
} | ||
$optionGroup = new CRM_Core_DAO_OptionGroup(); | ||
$optionGroup->copyValues($params);; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo with double ;;
@@ -44,7 +44,7 @@ public function testEnsureOptionGroupExistsNewValue() { | |||
|
|||
CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed Again']); | |||
$optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values']; | |||
$this->assertTrue(in_array('Bombed Again', $optionGroups)); | |||
$this->assertTrue(in_array('Bombed_Again', $optionGroups)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "bombed_again" - lower case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested
@seamuslee001 Just wanted to check that this won't stop you manually setting name via API / xml option group import? |
I don't think so but it would make it without spaces tho. |
Ok, that seems fine to me then |
…emove the name field from front end form as will be auto generated Ensure that option group names are lower csae Ensure that option group names are created as lower case and fix as per Justin's review
5fbf3d3
to
6ebc7a8
Compare
ok @jusfreeman have made those changes now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 looks good to me!
#merge-on-pass |
Merging as per review from @jusfreeman |
…emove the name field from front end form as will be auto generated
Overview
This removes the name field from the form to add a new option group as really it should be a calculated field. It also Ensures that option values are fixed on upgrade
Before
Option group names can be created with a space in it causing errors when trying to add new option valuse
After
All option group names are lower case and for new option groups created primarily on the basis of the title of the option group.
Agileware Ref: CIVICRM-1373
ping @eileenmcnaughton @colemanw @jusfreeman