setCheckPermissions($checkPermissions); } /** * @return \Civi\Api4\Generic\BasicGetFieldsAction */ abstract public static function getFields(); /** * Returns a list of permissions needed to access the various actions in this api. * * @return array */ public static function permissions() { $permissions = \CRM_Core_Permission::getEntityActionPermissions(); // For legacy reasons the permissions are keyed by lowercase entity name $lcentity = \CRM_Core_DAO_AllCoreTables::convertEntityNameToLower(self::getEntityName()); // Merge permissions for this entity with the defaults return ($permissions[$lcentity] ?? []) + $permissions['default']; } /** * Get entity name from called class * * @return string */ protected static function getEntityName() { return substr(static::class, strrpos(static::class, '\\') + 1); } /** * Overridable function to return a localized title for this entity. * * @return string */ protected static function getEntityTitle() { return static::getEntityName(); } /** * Magic method to return the action object for an api. * * @param string $action * @param array $args * @return AbstractAction * @throws NotImplementedException */ public static function __callStatic($action, $args) { $entity = self::getEntityName(); // Find class for this action $entityAction = "\\Civi\\Api4\\Action\\$entity\\" . ucfirst($action); if (class_exists($entityAction)) { $actionObject = new $entityAction($entity, $action); if (isset($args[0]) && $args[0] === FALSE) { $actionObject->setCheckPermissions(FALSE); } } else { throw new NotImplementedException("Api $entity $action version 4 does not exist."); } return $actionObject; } /** * Reflection function called by Entity::get() * * @see \Civi\Api4\Action\Entity\Get * @return array */ public static function getInfo() { $info = [ 'name' => static::getEntityName(), 'title' => static::getEntityTitle(), ]; $reflection = new \ReflectionClass(static::class); $info += ReflectionUtils::getCodeDocs($reflection, NULL, ['entity' => $info['name']]); unset($info['package'], $info['method']); return $info; } }