-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REF - Normalize internal format of permissions #29173
Conversation
Before: Permissions might be in associative or non-associative array format. After: Always associative regardless of how they are passed in from hook_civicrm_permission(). This also improves efficiency by only calling the hook once, and improves memory use by caching the array once.
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
Cool - should we start adding deprecation notices for the oldest of the 3 formats? |
@eileenmcnaughton we just did! This PR adds noisy deprecation for both old formats & you merged it so now it's official :) |
@colemanw oh right - that makes me a bit nervous - if you have an extension can you already change the keys from 0,1 to 'label'? No older versions access them from the numbers? Cos if they do people can't update their extensions ? |
@eileenmcnaughton The associative format has been supported for a long time... at least since Because the previous code never actually cared about the array keys it would just shift the first item off the array and take it as the label, then shift the second item as the description. |
There was a recent patch as part of civicrm#29173, so the version-number should be raised.
@@ -402,6 +402,9 @@ public function getAllModulePermissions(): array { | |||
// Convert them all to associative arrays. | |||
foreach ($permissions as $name => $defn) { | |||
$defn = (array) $defn; | |||
if (!isset($defn['label'])) { | |||
CRM_Core_Error::deprecatedWarning("Permission '$name' should be declared with 'label' and 'description' keys. See https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_permission/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool :)
Overview
Note for extension authors: Switching your extension's hook_civicrm_permissions to return the preferred format (with 'label' & 'description' array keys) will avoid deprecation notices added by this PR. It is safe to make that change without requiring the latest version of CiviCRM, as the preferred format is supported for every 5.x.x. version.
Historically, there have been 3 formats for defining a permission. This consolidates the format internally, while maintaining backward-support for the other two.
Includes a documentation update: https://lab.civicrm.org/documentation/docs/dev/-/merge_requests/1148
Before
Permissions added via hook might be in associative or non-associative array format, or they might be a plain string.
After
Internally they are now always associative regardless of how they are passed in from
hook_civicrm_permission()
.Deprecation notice issued for extensions that pass them in the old ways.
Technical Details
Deprecation notice added to alert extension devs to update the format.
This also improves efficiency by only calling the hook once, and improves memory use by caching the array once.