diff --git a/CRM/Core/BAO/ImportTemplateField.php b/CRM/Core/BAO/ImportTemplateField.php new file mode 100644 index 000000000000..4ccabdfc3417 --- /dev/null +++ b/CRM/Core/BAO/ImportTemplateField.php @@ -0,0 +1,66 @@ + 'save', + 'select' => ['name', 'label', 'description'], + 'where' => [ + ['usage', 'CONTAINS', 'import'], + ], + ]); + } + + /** + * Pseudoconstant callback for the 'entity' field + */ + public static function getImportableEntityOptions(string $fieldName, array $params):? array { + $values = $params['values']; + $userJobId = $values['user_job_id'] ?? NULL; + if (!$userJobId && !empty($values['id'])) { + $userJobId = CRM_Core_BAO_UserJob::getDbVal('user_job_id', $values['id']); + } + + if (!$userJobId) { + return NULL; + } + $entities = []; + $jobTypes = array_column(CRM_Core_BAO_UserJob::getTypes(), NULL, 'id'); + $jobType = CRM_Core_BAO_UserJob::getDbVal('job_type', $values['user_job_id']); + + $mainEntityName = $jobTypes[$jobType]['entity'] ?? NULL; + // TODO: For now each job type only supports one entity, + // so this select list doesn't (yet) have more than one option. + $entities[] = [ + 'id' => $mainEntityName, + 'name' => $mainEntityName, + 'label' => CoreUtil::getInfoItem($mainEntityName, 'title'), + 'icon' => CoreUtil::getInfoItem($mainEntityName, 'icon'), + ]; + + return $entities; + } + +} diff --git a/schema/Core/ImportTemplateField.entityType.php b/schema/Core/ImportTemplateField.entityType.php index 683e8b449aad..052dae578eb2 100644 --- a/schema/Core/ImportTemplateField.entityType.php +++ b/schema/Core/ImportTemplateField.entityType.php @@ -41,6 +41,10 @@ 'sql_type' => 'varchar(1024)', 'input_type' => 'Select', 'description' => ts('Template field key'), + 'pseudoconstant' => [ + 'callback' => ['CRM_Core_BAO_ImportTemplateField', 'getImportableFieldOptions'], + 'suffixes' => ['name', 'label', 'description'], + ], 'add' => '5.83', ], 'column_number' => [