From: Tim Otten Date: Fri, 11 Jun 2021 23:44:06 +0000 (-0700) Subject: DynamicFKAccessTrait - Emit explicit error-message for invalid table references X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=997e2e68599e7801f04dff8430f0ddc208422ea7;p=civicrm-core.git 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 --- 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;