Skip to content

Commit

Permalink
dev/core#81 (NFC) Fix warnings in custom group create
Browse files Browse the repository at this point in the history
  • Loading branch information
mickadoo committed Apr 26, 2018
1 parent dd8a0b6 commit d128501
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
32 changes: 16 additions & 16 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,37 @@ public static function create(&$params) {
$group->title = $params['title'];
}

if (in_array($params['extends'][0],
array(
'ParticipantRole',
'ParticipantEventName',
'ParticipantEventType',
)
)) {
$extends = CRM_Utils_Array::value('extends', $params, []);
$extendsEntity = CRM_Utils_Array::value(0, $extends);

$participantEntities = array(
'ParticipantRole',
'ParticipantEventName',
'ParticipantEventType',
);

if (in_array($extendsEntity, $participantEntities)) {
$group->extends = 'Participant';
}
else {
$group->extends = $params['extends'][0];
$group->extends = $extendsEntity;
}

$group->extends_entity_column_id = 'null';
if (
$params['extends'][0] == 'ParticipantRole' ||
$params['extends'][0] == 'ParticipantEventName' ||
$params['extends'][0] == 'ParticipantEventType'
if (in_array($extendsEntity, $participantEntities)
) {
$group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name');
$group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $extendsEntity, 'value', 'name');
}

//this is format when form get submit.
$extendsChildType = CRM_Utils_Array::value(1, $params['extends']);
$extendsChildType = CRM_Utils_Array::value(1, $extends);
//lets allow user to pass direct child type value, CRM-6893
if (!empty($params['extends_entity_column_value'])) {
$extendsChildType = $params['extends_entity_column_value'];
}
if (!CRM_Utils_System::isNull($extendsChildType)) {
$extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') {
if (CRM_Utils_Array::value(0, $extends) == 'Relationship') {
$extendsChildType = str_replace(array('_a_b', '_b_a'), array(
'',
'',
Expand Down Expand Up @@ -211,7 +211,7 @@ public static function create(&$params) {
$params['id'],
'table_name'
);
CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0]));
CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($extendsEntity));
}
$transaction->commit();

Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/api/v3/CustomGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,17 @@ public function testGetCustomGroupSuccess() {
}
}

public function testUpdateCustomGroup() {
$customGroup = $this->customGroupCreate();
$customGroupId = $customGroup['id'];

//update is_active
$params = ['id' => $customGroupId, 'is_active' => 0];
$result = $this->callAPISuccess('CustomGroup', 'create', $params);
$result = array_shift($result['values']);

$this->assertEquals(0, $result['is_active']);
$this->customGroupDelete($customGroupId);
}

}

0 comments on commit d128501

Please sign in to comment.