Skip to content

Commit

Permalink
CustomField.get - use CachedDAOGetAction
Browse files Browse the repository at this point in the history
  • Loading branch information
ufundo committed Dec 4, 2024
1 parent c0c5346 commit ce38bd8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Civi/Api4/Action/CustomField/Get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

namespace Civi\Api4\Action\CustomField;

/**
* @inheritDoc
*/
class Get extends \Civi\Api4\Generic\CachedDAOGetAction {

/**
* @inheritdoc
*
* Flatten field records from the CustomGroup cache
*/
protected function getCachedRecords(): array {
$groups = \CRM_Core_BAO_CustomGroup::getAll();
return array_merge(...array_map(fn ($group) => $group['fields'], $groups));
}

}
9 changes: 9 additions & 0 deletions Civi/Api4/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class CustomField extends Generic\DAOEntity {
use Generic\Traits\ManagedEntity;
use Generic\Traits\SortableEntity;

/**
* @param bool $checkPermissions
* @return Action\CustomField\Get
*/
public static function get($checkPermissions = TRUE) {
return (new Action\CustomField\Get(__CLASS__, __FUNCTION__))
->setCheckPermissions($checkPermissions);
}

/**
* @param bool $checkPermissions
* @return Action\CustomField\Create
Expand Down

0 comments on commit ce38bd8

Please sign in to comment.