* It may be poorly suited to recursive usage (e.g. permissions defined dynamically
* on top of permissions!) or during install/uninstall processes.
*
- * The list of permissions is generated via hook, and there is a standard/default
- * listener.
+ * The list of permissions is generated via hook, and there is a standard/default listener.
*
* @see CRM_Core_Permission_List
* @see \CRM_Utils_Hook::permissionList
*/
class Get extends BasicGetAction {
- public function getRecords() {
+ /**
+ * @return array[]
+ */
+ protected function getRecords() {
$cacheKey = 'list_' . $GLOBALS['tsLocale'];
if (!isset(\Civi::$statics[__CLASS__][$cacheKey])) {
$perms = [];
\CRM_Utils_Hook::permissionList($perms);
- foreach (array_keys($perms) as $permName) {
+ foreach ($perms as $permName => $permission) {
$defaults = [
'name' => $permName,
'group' => 'unknown',
'is_synthetic' => ($permName[0] === '@'),
'is_active' => TRUE,
];
- $perms[$permName] = array_merge($defaults, $perms[$permName]);
+ $perms[$permName] = array_merge($defaults, $permission);
}
\Civi::$statics[__CLASS__][$cacheKey] = $perms;
}
/**
* @param bool $checkPermissions
- * @return \Civi\Api4\Generic\BasicGetAction
+ * @return Action\Permission\Get
*/
public static function get($checkPermissions = TRUE) {
- return (new \Civi\Api4\Action\Permission\Get(__CLASS__, __FUNCTION__))->setCheckPermissions($checkPermissions);
+ return (new Action\Permission\Get(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
}
/**
[
'name' => 'group',
'title' => 'Group',
- 'required' => TRUE,
'data_type' => 'String',
],
[
'name' => 'name',
'title' => 'Name',
- 'required' => TRUE,
'data_type' => 'String',
],
[
'name' => 'title',
'title' => 'Title',
- 'required' => TRUE,
'data_type' => 'String',
],
[
'name' => 'description',
'title' => 'Description',
- 'required' => FALSE,
'data_type' => 'String',
],
[
'name' => 'is_synthetic',
'title' => 'Is Synthetic',
- 'required' => FALSE,
'data_type' => 'Boolean',
],
[
'title' => 'Is Active',
'description' => '',
'default' => TRUE,
- 'required' => FALSE,
'data_type' => 'Boolean',
],
];
/**
* @param bool $checkPermissions
- * @return \Civi\Api4\Generic\BasicGetAction
+ * @return Generic\BasicGetAction
*/
public static function get($checkPermissions = TRUE) {
- return (new \Civi\Api4\Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
- // Pulling from ::items() rather than DB -- because it provides the final/live/altered data.
- $items = \CRM_Core_Menu::items();
+ return (new Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
$result = [];
- foreach ($items as $path => $item) {
+ // Pulling from ::items() rather than DB -- because it provides the final/live/altered data.
+ foreach (\CRM_Core_Menu::items() as $path => $item) {
$result[] = ['path' => $path] + $item;
}
return $result;
[
'name' => 'path',
'title' => 'Relative Path',
- 'required' => TRUE,
'data_type' => 'String',
],
[
'name' => 'title',
'title' => 'Page Title',
- 'required' => TRUE,
'data_type' => 'String',
],
[
'name' => 'page_callback',
'title' => 'Page Callback',
- 'required' => TRUE,
'data_type' => 'String',
],
[
'name' => 'page_arguments',
'title' => 'Page Arguments',
- 'required' => FALSE,
'data_type' => 'String',
],
[
'name' => 'path_arguments',
'title' => 'Path Arguments',
- 'required' => FALSE,
'data_type' => 'String',
],
[
'name' => 'access_arguments',
'title' => 'Access Arguments',
- 'required' => FALSE,
'data_type' => 'Array',
],
];
$scope.helpContent = helpContent = formatHelp(content);
}
- // Convert plain-text help to markdown; replace variables and format links
+ // Format help text with markdown; replace variables and format links
function formatHelp(rawContent) {
function formatRefs(see) {
_.each(see, function(ref, idx) {
- var match = ref.match(/^\\Civi\\Api4\\([a-zA-Z]+)$/);
+ var match = ref.match(/^(\\Civi\\Api4\\)?([a-zA-Z]+)$/);
if (match) {
- ref = '#/explorer/' + match[1];
+ ref = '#/explorer/' + match[2];
}
- if (ref[0] === '\\') {
- ref = 'https://github.com/civicrm/civicrm-core/blob/master' + ref.replace(/\\/i, '/') + '.php';
+ // Link to php classes on GitHub.
+ // Fixme: Only works for files in the core repo
+ if (ref[0] === '\\' || ref.indexOf('Civi\\') === 0 || ref.indexOf('CRM_') === 0) {
+ var classFunction = _.trim(ref, '\\').split('::'),
+ replacement = new RegExp(classFunction[0].indexOf('CRM_') === 0 ? '_' : '\\\\', 'g');
+ ref = 'https://github.com/civicrm/civicrm-core/blob/master/' + classFunction[0].replace(replacement, '/') + '.php';
}
see[idx] = '<a target="' + (ref[0] === '#' ? '_self' : '_blank') + '" href="' + ref + '">' + see[idx] + '</a>';
});