3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Case_XMLProcessor_Process
extends CRM_Case_XMLProcessor
{
18 protected $defaultAssigneeOptionsValues = [];
23 * @param string $caseType
24 * @param array $params
26 * @throws CRM_Core_Exception
28 public function run($caseType, &$params) {
29 $xml = $this->retrieve($caseType);
32 $docLink = CRM_Utils_System
::docURL2("user/case-management/set-up");
33 throw new CRM_Core_Exception(ts("Configuration file could not be retrieved for case type = '%1' %2.",
34 [1 => $caseType, 2 => $docLink]
38 $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
39 $this->_isMultiClient
= $xmlProcessorProcess->getAllowMultipleCaseClients();
41 $this->process($xml, $params);
47 * @param bool $isLabel
48 * @param bool $maskAction
50 * @return array|bool|mixed
53 public function get($caseType, $fieldSet, $isLabel = FALSE, $maskAction = FALSE) {
54 $xml = $this->retrieve($caseType);
56 $docLink = CRM_Utils_System
::docURL2("user/case-management/set-up");
57 throw new CRM_Core_Exception(ts("Unable to load configuration file for the referenced case type: '%1' %2.",
58 [1 => $caseType, 2 => $docLink]
64 return $this->caseRoles($xml->CaseRoles
);
67 return $this->activitySets($xml->ActivitySets
);
70 return $this->activityTypes($xml->ActivityTypes
, FALSE, $isLabel, $maskAction);
76 * @param array $params
80 public function process($xml, &$params) {
81 $standardTimeline = $params['standardTimeline'] ??
NULL;
82 $activitySetName = $params['activitySetName'] ??
NULL;
84 if ('Open Case' == CRM_Utils_Array
::value('activityTypeName', $params)) {
85 // create relationships for the ones that are required
86 foreach ($xml->CaseRoles
as $caseRoleXML) {
87 foreach ($caseRoleXML->RelationshipType
as $relationshipTypeXML) {
88 // simplexml treats node values differently than you'd expect,
90 // Just using `if ($relationshipTypeXML->creator)` ends up always
91 // being true, so you have to cast to int or somehow force evaluation
92 // of the actual value. And casting to (bool) seems to behave
93 // differently on these objects than casting to (int).
94 if (!empty($relationshipTypeXML->creator
)) {
95 if (!$this->createRelationships($relationshipTypeXML,
99 throw new CRM_Core_Exception('Unable to create case relationships');
106 if ('Change Case Start Date' == CRM_Utils_Array
::value('activityTypeName', $params)) {
107 // delete all existing activities which are non-empty
108 $this->deleteEmptyActivity($params);
111 foreach ($xml->ActivitySets
as $activitySetsXML) {
112 foreach ($activitySetsXML->ActivitySet
as $activitySetXML) {
113 if ($standardTimeline) {
114 if (!empty($activitySetXML->timeline
)) {
115 return $this->processStandardTimeline($activitySetXML, $params);
118 elseif ($activitySetName) {
119 $name = (string) $activitySetXML->name
;
120 if ($name == $activitySetName) {
121 return $this->processActivitySet($activitySetXML, $params);
129 * @param $activitySetXML
130 * @param array $params
132 public function processStandardTimeline($activitySetXML, &$params) {
133 if ('Change Case Type' == CRM_Utils_Array
::value('activityTypeName', $params)
134 && CRM_Utils_Array
::value('resetTimeline', $params, TRUE)
136 // delete all existing activities which are non-empty
137 $this->deleteEmptyActivity($params);
140 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
141 foreach ($activityTypesXML as $activityTypeXML) {
142 $this->createActivity($activityTypeXML, $params);
148 * @param $activitySetXML
149 * @param array $params
151 public function processActivitySet($activitySetXML, &$params) {
152 foreach ($activitySetXML->ActivityTypes
as $activityTypesXML) {
153 foreach ($activityTypesXML as $activityTypeXML) {
154 $this->createActivity($activityTypeXML, $params);
160 * @param $caseRolesXML
161 * @param bool $isCaseManager
163 * @return array|mixed
165 public function &caseRoles($caseRolesXML, $isCaseManager = FALSE) {
166 // Look up relationship types according to the XML convention (described
167 // from perspective of non-client) but return the labels according to the UI
168 // convention (described from perspective of client)
169 $relationshipTypesToReturn = &$this->allRelationshipTypes(FALSE);
172 foreach ($caseRolesXML as $caseRoleXML) {
173 foreach ($caseRoleXML->RelationshipType
as $relationshipTypeXML) {
174 list($relationshipTypeID,) = $this->locateNameOrLabel($relationshipTypeXML);
175 if ($relationshipTypeID === FALSE) {
179 if (!$isCaseManager) {
180 $result[$relationshipTypeID] = $relationshipTypesToReturn[$relationshipTypeID];
182 elseif ($relationshipTypeXML->manager
== 1) {
183 return $relationshipTypeID;
191 * @param SimpleXMLElement $relationshipTypeXML
192 * @param array $params
195 * @throws CRM_Core_Exception
197 public function createRelationships($relationshipTypeXML, $params) {
198 // get the relationship
199 [$relationshipType, $relationshipTypeName] = $this->locateNameOrLabel($relationshipTypeXML);
200 if ($relationshipType === FALSE) {
201 $docLink = CRM_Utils_System
::docURL2("user/case-management/set-up");
202 throw new CRM_Core_Exception(ts('Relationship type %1, found in case configuration file, is not present in the database %2',
203 [1 => $relationshipTypeName, 2 => $docLink]
207 $clients = (array) $params['clientID'];
208 $relationshipValues = [];
210 foreach ($clients as $clientId) {
211 // $relationshipType string ends in either `_a_b` or `_b_a`
212 $a = substr($relationshipType, -3, 1);
213 $b = substr($relationshipType, -1);
214 $relationshipValues[] = [
215 'relationship_type_id' => substr($relationshipType, 0, -4),
217 'case_id' => $params['caseID'],
218 'start_date' => date("Ymd"),
219 'end_date' => $params['relationship_end_date'] ??
NULL,
220 "contact_id_$a" => $clientId,
221 "contact_id_$b" => $params['creatorID'],
225 //\Civi\Api4\Relationship::save(FALSE)
226 // ->setRecords($relationshipValues)
227 // ->setMatch(['case_id', 'relationship_type_id', 'contact_id_a', 'contact_id_b'])
229 // FIXME: The above api code would be better, but doesn't work
230 // See discussion in https://github.com/civicrm/civicrm-core/pull/15030
231 foreach ($relationshipValues as $params) {
232 $dao = new CRM_Contact_DAO_Relationship();
233 $dao->copyValues($params);
234 // only create a relationship if it does not exist
235 if (!$dao->find(TRUE)) {
236 CRM_Contact_BAO_Relationship
::add($params);
244 * @param $activityTypesXML
245 * @param bool $maxInst
246 * @param bool $isLabel
247 * @param bool $maskAction
251 public function activityTypes($activityTypesXML, $maxInst = FALSE, $isLabel = FALSE, $maskAction = FALSE) {
252 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType(TRUE, TRUE);
254 foreach ($activityTypesXML as $activityTypeXML) {
255 foreach ($activityTypeXML as $recordXML) {
256 $activityTypeName = (string) $recordXML->name
;
257 $maxInstances = (string) $recordXML->max_instances
;
258 $activityTypeInfo = $activityTypes[$activityTypeName] ??
NULL;
260 if ($activityTypeInfo['id']) {
262 if ($maskAction == 'edit' && '0' === (string) $recordXML->editable
) {
263 $result[$maskAction][] = $activityTypeInfo['id'];
268 //if we want,labels of activities should be returned.
270 $result[$activityTypeInfo['id']] = $activityTypeInfo['label'];
273 $result[$activityTypeInfo['id']] = $activityTypeName;
278 $result[$activityTypeName] = $maxInstances;
286 // call option value hook
287 CRM_Utils_Hook
::optionValues($result, 'case_activity_type');
293 * @param SimpleXMLElement $caseTypeXML
295 * @return array<string> symbolic activity-type names
297 public function getDeclaredActivityTypes($caseTypeXML) {
300 if (!empty($caseTypeXML->ActivityTypes
) && $caseTypeXML->ActivityTypes
->ActivityType
) {
301 foreach ($caseTypeXML->ActivityTypes
->ActivityType
as $activityTypeXML) {
302 $result[] = (string) $activityTypeXML->name
;
306 if (!empty($caseTypeXML->ActivitySets
) && $caseTypeXML->ActivitySets
->ActivitySet
) {
307 foreach ($caseTypeXML->ActivitySets
->ActivitySet
as $activitySetXML) {
308 if ($activitySetXML->ActivityTypes
&& $activitySetXML->ActivityTypes
->ActivityType
) {
309 foreach ($activitySetXML->ActivityTypes
->ActivityType
as $activityTypeXML) {
310 $result[] = (string) $activityTypeXML->name
;
316 $result = array_unique($result);
322 * Relationships are straight from XML, described from perspective of non-client
324 * @param SimpleXMLElement $caseTypeXML
326 * @return array<string> symbolic relationship-type names
328 public function getDeclaredRelationshipTypes($caseTypeXML) {
331 if (!empty($caseTypeXML->CaseRoles
) && $caseTypeXML->CaseRoles
->RelationshipType
) {
332 foreach ($caseTypeXML->CaseRoles
->RelationshipType
as $relTypeXML) {
333 list(, $relationshipTypeMachineName) = $this->locateNameOrLabel($relTypeXML);
334 $result[] = $relationshipTypeMachineName;
338 $result = array_unique($result);
344 * @param array $params
346 public function deleteEmptyActivity(&$params) {
347 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
348 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
352 FROM civicrm_activity a
353 INNER JOIN civicrm_activity_contact t ON t.activity_id = a.id
354 INNER JOIN civicrm_case_activity ca on ca.activity_id = a.id
355 WHERE t.contact_id = %1
356 AND t.record_type_id = $targetID
358 AND a.is_current_revision = 1
361 $sqlParams = [1 => [$params['clientID'], 'Integer'], 2 => [$params['caseID'], 'Integer']];
362 CRM_Core_DAO
::executeQuery($query, $sqlParams);
366 * @param array $params
370 public function isActivityPresent(&$params) {
373 FROM civicrm_activity a
374 INNER JOIN civicrm_case_activity ca on ca.activity_id = a.id
375 WHERE a.activity_type_id = %1
381 1 => [$params['activityTypeID'], 'Integer'],
382 2 => [$params['caseID'], 'Integer'],
384 $count = CRM_Core_DAO
::singleValueQuery($query, $sqlParams);
386 // check for max instance
387 $caseType = CRM_Case_BAO_Case
::getCaseType($params['caseID'], 'name');
388 $maxInstance = self
::getMaxInstance($caseType, $params['activityTypeName']);
390 return $maxInstance ?
($count < $maxInstance ?
FALSE : TRUE) : FALSE;
394 * @param $activityTypeXML
395 * @param array $params
398 * @throws CRM_Core_Exception
401 public function createActivity($activityTypeXML, &$params) {
402 $activityTypeName = (string) $activityTypeXML->name
;
403 $activityTypes = CRM_Case_PseudoConstant
::caseActivityType(TRUE, TRUE);
404 $activityTypeInfo = $activityTypes[$activityTypeName] ??
NULL;
406 if (!$activityTypeInfo) {
407 $docLink = CRM_Utils_System
::docURL2("user/case-management/set-up");
408 throw new CRM_Core_Exception(ts('Activity type %1, found in case configuration file, is not present in the database %2',
409 [1 => $activityTypeName, 2 => $docLink]
413 $activityTypeID = $activityTypeInfo['id'];
415 if (isset($activityTypeXML->status
)) {
416 $statusName = (string) $activityTypeXML->status
;
419 $statusName = 'Scheduled';
422 $client = (array) $params['clientID'];
426 if (isset($activityTypeXML->order
)) {
427 $orderVal = (string) $activityTypeXML->order
;
430 if ($activityTypeName == 'Open Case') {
432 'activity_type_id' => $activityTypeID,
433 'source_contact_id' => $params['creatorID'],
435 'is_current_revision' => 1,
436 'subject' => !empty($params['subject']) ?
$params['subject'] : $activityTypeName,
437 'status_id' => CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', $statusName),
438 'target_contact_id' => $client,
439 'medium_id' => $params['medium_id'] ??
NULL,
440 'location' => $params['location'] ??
NULL,
441 'details' => $params['details'] ??
NULL,
442 'duration' => $params['duration'] ??
NULL,
443 'weight' => $orderVal,
448 'activity_type_id' => $activityTypeID,
449 'source_contact_id' => $params['creatorID'],
451 'is_current_revision' => 1,
452 'status_id' => CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', $statusName),
453 'target_contact_id' => $client,
454 'weight' => $orderVal,
458 $activityParams['assignee_contact_id'] = $this->getDefaultAssigneeForActivity($activityParams, $activityTypeXML, $params['caseID']);
460 //parsing date to default preference format
461 $params['activity_date_time'] = CRM_Utils_Date
::processDate($params['activity_date_time']);
463 if ($activityTypeName == 'Open Case') {
464 // we don't set activity_date_time for auto generated
465 // activities, but we want it to be set for open case.
466 $activityParams['activity_date_time'] = $params['activity_date_time'];
467 if (array_key_exists('custom', $params) && is_array($params['custom'])) {
468 $activityParams['custom'] = $params['custom'];
471 // Add parameters for attachments
473 $numAttachments = Civi
::settings()->get('max_attachments');
474 for ($i = 1; $i <= $numAttachments; $i++
) {
475 $attachName = "attachFile_$i";
476 if (isset($params[$attachName]) && !empty($params[$attachName])) {
477 $activityParams[$attachName] = $params[$attachName];
482 $activityDate = NULL;
483 //get date of reference activity if set.
484 if ($referenceActivityName = (string) $activityTypeXML->reference_activity
) {
486 //we skip open case as reference activity.CRM-4374.
487 if (!empty($params['resetTimeline']) && $referenceActivityName == 'Open Case') {
488 $activityDate = $params['activity_date_time'];
491 $referenceActivityInfo = $activityTypes[$referenceActivityName] ??
NULL;
492 if ($referenceActivityInfo['id']) {
493 $caseActivityParams = ['activity_type_id' => $referenceActivityInfo['id']];
495 //if reference_select is set take according activity.
496 if ($referenceSelect = (string) $activityTypeXML->reference_select
) {
497 $caseActivityParams[$referenceSelect] = 1;
500 $referenceActivity = CRM_Case_BAO_Case
::getCaseActivityDates($params['caseID'], $caseActivityParams, TRUE);
502 if (is_array($referenceActivity)) {
503 foreach ($referenceActivity as $aId => $details) {
504 $activityDate = $details['activity_date'] ??
NULL;
511 if (!$activityDate) {
512 $activityDate = $params['activity_date_time'];
514 list($activity_date, $activity_time) = CRM_Utils_Date
::setDateDefaults($activityDate);
515 $activityDateTime = CRM_Utils_Date
::processDate($activity_date, $activity_time);
516 //add reference offset to date.
517 if ((int) $activityTypeXML->reference_offset
) {
518 $activityDateTime = CRM_Utils_Date
::intervalAdd('day', (int) $activityTypeXML->reference_offset
,
523 $activityParams['activity_date_time'] = CRM_Utils_Date
::format($activityDateTime);
526 // if same activity is already there, skip and dont touch
527 $params['activityTypeID'] = $activityTypeID;
528 $params['activityTypeName'] = $activityTypeName;
529 if ($this->isActivityPresent($params)) {
532 $activityParams['case_id'] = $params['caseID'];
533 if (!empty($activityParams['is_auto'])) {
534 $activityParams['skipRecentView'] = TRUE;
537 // @todo - switch to using api & remove the parameter pre-wrangling above.
538 $activity = CRM_Activity_BAO_Activity
::create($activityParams);
541 throw new CRM_Core_Exception('Unable to create Activity');
544 // create case activity record
546 'activity_id' => $activity->id
,
547 'case_id' => $params['caseID'],
549 CRM_Case_BAO_Case
::processCaseActivity($caseParams);
554 * Return the default assignee contact for the activity.
556 * @param array $activityParams
557 * @param object $activityTypeXML
560 * @return int|null the ID of the default assignee contact or null if none.
562 protected function getDefaultAssigneeForActivity($activityParams, $activityTypeXML, $caseId) {
563 if (!isset($activityTypeXML->default_assignee_type
)) {
567 $defaultAssigneeOptionsValues = $this->getDefaultAssigneeOptionValues();
569 switch ($activityTypeXML->default_assignee_type
) {
570 case $defaultAssigneeOptionsValues['BY_RELATIONSHIP']:
571 return $this->getDefaultAssigneeByRelationship($activityParams, $activityTypeXML, $caseId);
574 case $defaultAssigneeOptionsValues['SPECIFIC_CONTACT']:
575 return $this->getDefaultAssigneeBySpecificContact($activityTypeXML);
578 case $defaultAssigneeOptionsValues['USER_CREATING_THE_CASE']:
579 return $activityParams['source_contact_id'];
582 case $defaultAssigneeOptionsValues['NONE']:
589 * Fetches and caches the activity's default assignee options.
593 protected function getDefaultAssigneeOptionValues() {
594 if (!empty($this->defaultAssigneeOptionsValues
)) {
595 return $this->defaultAssigneeOptionsValues
;
598 $defaultAssigneeOptions = civicrm_api3('OptionValue', 'get', [
599 'option_group_id' => 'activity_default_assignee',
600 'options' => ['limit' => 0],
603 foreach ($defaultAssigneeOptions['values'] as $option) {
604 $this->defaultAssigneeOptionsValues
[$option['name']] = $option['value'];
607 return $this->defaultAssigneeOptionsValues
;
611 * Returns the default assignee for the activity by searching for the target's
612 * contact relationship type defined in the activity's details.
614 * @param array $activityParams
615 * @param object $activityTypeXML
618 * @return int|null the ID of the default assignee contact or null if none.
620 protected function getDefaultAssigneeByRelationship($activityParams, $activityTypeXML, $caseId) {
621 $isDefaultRelationshipDefined = isset($activityTypeXML->default_assignee_relationship
)
622 && preg_match('/\d+_[ab]_[ab]/', $activityTypeXML->default_assignee_relationship
);
624 if (!$isDefaultRelationshipDefined) {
628 $targetContactId = is_array($activityParams['target_contact_id'])
629 ? CRM_Utils_Array
::first($activityParams['target_contact_id'])
630 : $activityParams['target_contact_id'];
631 list($relTypeId, $a, $b) = explode('_', $activityTypeXML->default_assignee_relationship
);
634 'relationship_type_id' => $relTypeId,
635 "contact_id_$b" => $targetContactId,
637 'case_id' => $caseId,
638 'options' => ['limit' => 1],
641 if ($this->isBidirectionalRelationshipType($relTypeId)) {
642 $params["contact_id_$a"] = $targetContactId;
643 $params['options']['or'] = [['contact_id_a', 'contact_id_b']];
646 $relationships = civicrm_api3('Relationship', 'get', $params);
647 if (empty($relationships['count'])) {
648 $params['case_id'] = ['IS NULL' => 1];
649 $relationships = civicrm_api3('Relationship', 'get', $params);
652 if ($relationships['count']) {
653 $relationship = CRM_Utils_Array
::first($relationships['values']);
655 // returns the contact id on the other side of the relationship:
656 return (int) $relationship['contact_id_a'] === (int) $targetContactId
657 ?
$relationship['contact_id_b']
658 : $relationship['contact_id_a'];
666 * Determines if the given relationship type is bidirectional or not by
667 * comparing their labels.
671 protected function isBidirectionalRelationshipType($relationshipTypeId) {
672 $relationshipTypeResult = civicrm_api3('RelationshipType', 'get', [
673 'id' => $relationshipTypeId,
674 'options' => ['limit' => 1],
677 if ($relationshipTypeResult['count'] === 0) {
681 $relationshipType = CRM_Utils_Array
::first($relationshipTypeResult['values']);
683 return $relationshipType['label_b_a'] === $relationshipType['label_a_b'];
687 * Returns the activity's default assignee for a specific contact if the contact exists,
688 * otherwise returns null.
690 * @param object $activityTypeXML
694 protected function getDefaultAssigneeBySpecificContact($activityTypeXML) {
695 if (!$activityTypeXML->default_assignee_contact
) {
699 $contact = civicrm_api3('Contact', 'get', [
700 'id' => $activityTypeXML->default_assignee_contact
,
703 if ($contact['count'] == 1) {
704 return $activityTypeXML->default_assignee_contact
;
711 * @param $activitySetsXML
715 public static function activitySets($activitySetsXML) {
717 foreach ($activitySetsXML as $activitySetXML) {
718 foreach ($activitySetXML as $recordXML) {
719 $activitySetName = (string) $recordXML->name
;
720 $activitySetLabel = (string) $recordXML->label
;
721 $result[$activitySetName] = $activitySetLabel;
730 * @param string|null $activityTypeName
732 * @return array|bool|mixed
733 * @throws CRM_Core_Exception
735 public function getMaxInstance($caseType, $activityTypeName = NULL) {
736 $xml = $this->retrieve($caseType);
738 if ($xml === FALSE) {
739 throw new CRM_Core_Exception('Unable to locate xml definition for case type ' . $caseType);
742 $activityInstances = $this->activityTypes($xml->ActivityTypes
, TRUE);
743 return $activityTypeName ? CRM_Utils_Array
::value($activityTypeName, $activityInstances) : $activityInstances;
749 * @return array|mixed
751 public function getCaseManagerRoleId($caseType) {
752 $xml = $this->retrieve($caseType);
753 return $this->caseRoles($xml->CaseRoles
, TRUE);
757 * @param string $caseType
759 * @return array<\Civi\CCase\CaseChangeListener>
761 public function getListeners($caseType) {
762 $xml = $this->retrieve($caseType);
764 if ($xml->Listeners
&& $xml->Listeners
->Listener
) {
765 foreach ($xml->Listeners
->Listener
as $listenerXML) {
766 $class = (string) $listenerXML;
767 $listeners[] = new $class();
776 public function getRedactActivityEmail() {
777 return $this->getBoolSetting('civicaseRedactActivityEmail', 'RedactActivityEmail');
781 * Retrieves AllowMultipleCaseClients setting.
784 * 1 if allowed, 0 if not
786 public function getAllowMultipleCaseClients() {
787 return $this->getBoolSetting('civicaseAllowMultipleClients', 'AllowMultipleCaseClients');
791 * Retrieves NaturalActivityTypeSort setting.
794 * 1 if natural, 0 if alphabetic
796 public function getNaturalActivityTypeSort() {
797 return $this->getBoolSetting('civicaseNaturalActivityTypeSort', 'NaturalActivityTypeSort');
801 * @param string $settingKey
802 * @param string $xmlTag
803 * @param mixed $default
807 private function getBoolSetting($settingKey, $xmlTag, $default = 0) {
808 $setting = Civi
::settings()->get($settingKey);
809 if ($setting !== 'default') {
810 return (int) $setting;
812 if ($xml = $this->retrieve("Settings")) {
813 return (string) $xml->{$xmlTag} ?
1 : 0;
819 * At some point name and label got mixed up for case roles.
820 * Check against known machine name values, and then if no match check
822 * This is subject to some edge cases, but we catch those with a system
824 * We do this to avoid requiring people to update their xml files which can
825 * be stored in external files we can't/don't want to edit.
827 * @param SimpleXMLElement $xml
829 * @return array[bool|string,string]
831 public function locateNameOrLabel($xml) {
832 $lookupString = (string) $xml->name
;
834 // Don't use pseudoconstant because we need everything both name and
835 // label and disabled types.
836 $relationshipTypes = civicrm_api3('RelationshipType', 'get', [
837 'options' => ['limit' => 0],
840 // First look and see if it matches a machine name in the system.
841 // There are some edge cases here where we've actually been passed in a
842 // display label and it happens to match the machine name for a different
843 // db entry, but we have a system status check.
844 // But, we do want to check against the a_b version first, because of the
845 // way direction matters and that for bidirectional only one is present in
846 // the list where this eventually gets used, so return that first.
847 $relationshipTypeMachineNames = array_column($relationshipTypes, 'id', 'name_a_b');
848 if (isset($relationshipTypeMachineNames[$lookupString])) {
849 return ["{$relationshipTypeMachineNames[$lookupString]}_b_a", $lookupString];
851 $relationshipTypeMachineNames = array_column($relationshipTypes, 'id', 'name_b_a');
852 if (isset($relationshipTypeMachineNames[$lookupString])) {
853 return ["{$relationshipTypeMachineNames[$lookupString]}_a_b", $lookupString];
856 // Now at this point assume we've been passed a display label, so find
857 // what it matches and return the associated machine name. This is a bit
858 // trickier because suppose somebody has changed the display labels so
859 // that they are now the same, but the machine names are different. We
860 // don't know which to return and so while it's the right relationship type
861 // it might be the backwards direction. We have to pick one to try first.
863 $relationshipTypeDisplayLabels = array_column($relationshipTypes, 'id', 'label_a_b');
864 if (isset($relationshipTypeDisplayLabels[$lookupString])) {
866 "{$relationshipTypeDisplayLabels[$lookupString]}_b_a",
867 $relationshipTypes[$relationshipTypeDisplayLabels[$lookupString]]['name_a_b'],
870 $relationshipTypeDisplayLabels = array_column($relationshipTypes, 'id', 'label_b_a');
871 if (isset($relationshipTypeDisplayLabels[$lookupString])) {
873 "{$relationshipTypeDisplayLabels[$lookupString]}_a_b",
874 $relationshipTypes[$relationshipTypeDisplayLabels[$lookupString]]['name_b_a'],
878 // Just go with what we were passed in, even though it doesn't seem
879 // to match *anything*. This was what it did before.
880 return [FALSE, $lookupString];