+ /**
+ * Given a key value that we know is a foreign key to another table, return
+ * what the DAO thinks is the "label" for the foreign entity. For example
+ * if it's referencing a contact then return the contact name, or if it's an
+ * activity then return the activity subject.
+ * If it's the type of DAO that doesn't have such a thing, just echo back
+ * what we were given.
+ *
+ * @param string $fkClassName
+ * @param string $field
+ * @param int $keyval
+ * @return string
+ */
+ private function convertForeignKeyValuesToLabels(string $fkClassName, string $field, int $keyval): string {
+ if (property_exists($fkClassName, '_labelField')) {
+ $labelValue = CRM_Core_DAO::getFieldValue($fkClassName, $keyval, $fkClassName::$_labelField);
+ // Not sure if this should use ts - there's not a lot of context (`%1 (id: %2)`) - and also the similar field labels above don't use ts.
+ return "{$labelValue} (id: {$keyval})";
+ }
+ return (string) $keyval;
+ }
+