protected function GroupPermissionHandler::buildPermissionsYaml in Group 8
Same name and namespace in other branches
- 2.0.x src/Access/GroupPermissionHandler.php \Drupal\group\Access\GroupPermissionHandler::buildPermissionsYaml()
Builds all permissions provided by .group.permissions.yml files.
Return value
array[] An array of permissions as described in ::getPermissions().
See also
\Drupal\group\Access\PermissionHandlerInterface::getPermissions()
2 calls to GroupPermissionHandler::buildPermissionsYaml()
- GroupPermissionHandler::getPermissions in src/
Access/ GroupPermissionHandler.php - Gets all defined group permissions.
- GroupPermissionHandler::getPermissionsByGroupType in src/
Access/ GroupPermissionHandler.php - Gets all defined group permissions for a group type.
File
- src/
Access/ GroupPermissionHandler.php, line 199
Class
- GroupPermissionHandler
- Provides the available permissions based on yml files.
Namespace
Drupal\group\AccessCode
protected function buildPermissionsYaml() {
$all_permissions = [];
$all_callback_permissions = [];
foreach ($this
->getYamlDiscovery()
->findAll() as $provider => $permissions) {
// The top-level 'permissions_callback' is a list of methods in controller
// syntax, see \Drupal\Core\Controller\ControllerResolver. These methods
// should return an array of permissions in the same structure.
if (isset($permissions['permission_callbacks'])) {
foreach ($permissions['permission_callbacks'] as $permission_callback) {
$callback = $this->controllerResolver
->getControllerFromDefinition($permission_callback);
if ($callback_permissions = call_user_func($callback)) {
// Add any callback permissions to the array of permissions. In case
// of any conflict, the YAML ones will take precedence.
foreach ($callback_permissions as $name => $callback_permission) {
if (!is_array($callback_permission)) {
$callback_permission = [
'title' => $callback_permission,
];
}
// Set the provider if none was specified.
$callback_permission += [
'provider' => $provider,
];
// Set the section if none was specified.
$callback_permission += [
'section' => 'General',
];
$all_callback_permissions[$name] = $callback_permission;
}
}
}
unset($permissions['permission_callbacks']);
}
foreach ($permissions as $permission_name => $permission) {
if (!is_array($permission)) {
$permission = [
'title' => $permission,
];
}
// Set the provider if none was specified.
$permission += [
'provider' => $provider,
];
// Set the section if none was specified.
$permission += [
'section' => 'General',
];
$permissions[$permission_name] = $permission;
}
$all_permissions += $permissions;
}
// Combine all defined permissions and set the rest of the defaults.
$full_permissions = $all_permissions + $all_callback_permissions;
foreach ($full_permissions as $permission_name => $permission) {
$full_permissions[$permission_name] = $this
->completePermission($permission);
}
return $full_permissions;
}