Skip to content

Commit

Permalink
[php8-compact][REF] Fix failing custom group test on php8 by better h…
Browse files Browse the repository at this point in the history
…andling strings in 2nd key of the extends array and also validating the child and main entity work
  • Loading branch information
seamuslee001 committed Jun 16, 2021
1 parent c6aacd0 commit 54a1943
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 34 deletions.
51 changes: 50 additions & 1 deletion CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,21 @@ public static function create(&$params) {
$extendsChildType = $params['extends_entity_column_value'];
}
if (!CRM_Utils_System::isNull($extendsChildType)) {
$extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType);
$registeredSubTypes = self::getSubTypes()[$extendsEntity];
if (is_array($extendsChildType)) {
foreach ($extendsChildType as $childType) {
if (!array_key_exists($childType, $registeredSubTypes) && !in_array($childType, $registeredSubTypes, TRUE)) {
throw new CRM_Core_Exception('Supplied Sub type is not valid for the specified entitiy');
}
}
}
else {
if (!array_key_exists($extendsChildType, $registeredSubTypes) && !in_array($extendsChildType, $registeredSubTypes, TRUE)) {
throw new CRM_Core_Exception('Supplied Sub type is not valid for the specified entitiy');
}
$extendsChildType = [$extendsChildType];
}
$extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $extendsChildType);
if (CRM_Utils_Array::value(0, $extends) == 'Relationship') {
$extendsChildType = str_replace(['_a_b', '_b_a'], [
'',
Expand Down Expand Up @@ -2200,4 +2214,39 @@ private static function buildGroupTree($entityType, $toReturn, $subTypes, $query
return [$multipleFieldGroups, $groupTree];
}

public static function getSubTypes(): array {
$sel2 = [];
$activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);

$eventType = CRM_Core_OptionGroup::values('event_type');
$grantType = CRM_Core_OptionGroup::values('grant_type');
$campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
$participantRole = CRM_Core_OptionGroup::values('participant_role');

asort($activityType);
asort($eventType);
asort($grantType);
asort($membershipType);
asort($participantRole);

$sel2['Event'] = $eventType;
$sel2['Grant'] = $grantType;
$sel2['Activity'] = $activityType;
$sel2['Campaign'] = $campaignTypes;
$sel2['Membership'] = $membershipType;
$sel2['ParticipantRole'] = $participantRole;
$sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
$sel2['ParticipantEventType'] = $eventType;
$sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
$sel2['Relationship'] = CRM_Custom_Form_Group::getRelationshipTypes();

$sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
$sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
$sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);

CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2);
return $sel2;
}

}
32 changes: 1 addition & 31 deletions CRM/Custom/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,38 +176,8 @@ public function buildQuickForm() {
$this->assign('contactTypes', json_encode($contactTypes));

$sel1 = ["" => ts("- select -")] + CRM_Core_SelectValues::customGroupExtends();
$sel2 = [];
$activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);

$eventType = CRM_Core_OptionGroup::values('event_type');
$grantType = CRM_Core_OptionGroup::values('grant_type');
$campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
$membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
$participantRole = CRM_Core_OptionGroup::values('participant_role');

ksort($sel1);
asort($activityType);
asort($eventType);
asort($grantType);
asort($membershipType);
asort($participantRole);

$sel2['Event'] = $eventType;
$sel2['Grant'] = $grantType;
$sel2['Activity'] = $activityType;
$sel2['Campaign'] = $campaignTypes;
$sel2['Membership'] = $membershipType;
$sel2['ParticipantRole'] = $participantRole;
$sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
$sel2['ParticipantEventType'] = $eventType;
$sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
$sel2['Relationship'] = self::getRelationshipTypes();

$sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
$sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
$sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);

CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2);
$sel2 = CRM_Core_BAO_CustomGroup::getSubTypes();

foreach ($sel2 as $main => $sub) {
if (!empty($sel2[$main])) {
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/api/v3/CustomGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ public function testCustomGroupExtendsMultipleCreate() {
'is_active' => 1,
];

$result = $this->callAPIFailure('custom_group', 'create', $params,
'implode(): Invalid arguments passed');
$result = $this->callAPIFailure('custom_group', 'create', $params, 'Supplied Sub type is not valid for the specified entitiy');
}

/**
Expand Down

0 comments on commit 54a1943

Please sign in to comment.