From 997e2e68599e7801f04dff8430f0ddc208422ea7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 11 Jun 2021 16:44:06 -0700 Subject: [PATCH] DynamicFKAccessTrait - Emit explicit error-message for invalid table references Use-Case: You create a dynamic FK with a reference to an invalid table. Before: Returns an API error/exception about type-matching (string vs null) After: Returns an API error/exception about the invalid reference --- CRM/Core/DynamicFKAccessTrait.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CRM/Core/DynamicFKAccessTrait.php b/CRM/Core/DynamicFKAccessTrait.php index 041d53717d..041ec3741e 100644 --- a/CRM/Core/DynamicFKAccessTrait.php +++ b/CRM/Core/DynamicFKAccessTrait.php @@ -39,6 +39,10 @@ trait CRM_Core_DynamicFKAccessTrait { } if ($eid && $table) { $targetEntity = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getClassForTable($table)); + if ($targetEntity === NULL) { + throw new \API_Exception(sprintf('Cannot resolve permissions for dynamic foreign key in "%s". Invalid table reference "%s".', + static::getTableName(), $table)); + } return \Civi\Api4\Utils\CoreUtil::checkAccessDelegated($targetEntity, 'update', ['id' => $eid], $userID); } return TRUE; -- 2.25.1