- if (!empty($field['pseudoconstant']) && !empty($field['pseudoconstant']['optionGroupName'])) {
- $fields[$field['pseudoconstant']['optionGroupName']] = array(
- 'title' => CRM_Core_BAO_OptionGroup::getTitleByName($field['pseudoconstant']['optionGroupName']),
- 'name' => $field['pseudoconstant']['optionGroupName'],
- 'data_type' => CRM_Utils_Type::T_STRING,
- );
+ if (!empty($field['pseudoconstant'])) {
+ $pseudoConstant = $field['pseudoconstant'];
+ if (!empty($pseudoConstant['optionGroupName'])) {
+ $fields[$pseudoConstant['optionGroupName']] = [
+ 'title' => CRM_Core_BAO_OptionGroup::getTitleByName($pseudoConstant['optionGroupName']),
+ 'name' => $pseudoConstant['optionGroupName'],
+ 'data_type' => CRM_Utils_Type::T_STRING,
+ 'is_pseudofield_for' => $field['name'],
+ ];
+ }
+ // We restrict to id + name + FK as we are extending this a bit, but cautiously.
+ elseif (
+ !empty($field['FKClassName'])
+ && CRM_Utils_Array::value('keyColumn', $pseudoConstant) === 'id'
+ && CRM_Utils_Array::value('labelColumn', $pseudoConstant) === 'name'
+ ) {
+ $pseudoFieldName = str_replace('_' . $pseudoConstant['keyColumn'], '', $field['name']);
+ // This if is just an extra caution when adding change.
+ if (!isset($fields[$pseudoFieldName])) {
+ $daoName = $field['FKClassName'];
+ $fkFields = $daoName::fields();
+ foreach ($fkFields as $fkField) {
+ if ($fkField['name'] === $pseudoConstant['labelColumn']) {
+ $fields[$pseudoFieldName] = [
+ 'name' => $pseudoFieldName,
+ 'is_pseudofield_for' => $field['name'],
+ 'title' => $fkField['title'],
+ 'data_type' => $fkField['type'],
+ 'where' => $field['where'],
+ ];
+ }
+ }
+ }
+ }