3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Trait for with entities with an entity_table + entity_id dynamic FK.
21 trait CRM_Core_DynamicFKAccessTrait
{
24 * @param string $action
25 * @param array $record
26 * @param int|NULL $userID
28 * @see CRM_Core_DAO::checkAccess
30 public static function _checkAccess(string $action, array $record, $userID): bool {
31 $eid = $record['entity_id'] ??
NULL;
32 $table = $record['entity_table'] ??
NULL;
33 if (!$eid && !empty($record['id'])) {
34 $eid = CRM_Core_DAO
::getFieldValue(__CLASS__
, $record['id'], 'entity_id');
36 if ($eid && !$table && !empty($record['id'])) {
37 $table = CRM_Core_DAO
::getFieldValue(__CLASS__
, $record['id'], 'entity_table');
40 $bao = CRM_Core_DAO_AllCoreTables
::getBAOClassName(CRM_Core_DAO_AllCoreTables
::getClassForTable($table));
41 return $bao::checkAccess(CRM_Core_Permission
::EDIT
, ['id' => $eid], $userID);