-
Improvement
-
Resolution: Fixed
-
Major
-
4.1
NOTE: this issue used to be about simplifying adding of new context levels, that is not the case any more, patch is now only refactoring of context classes
There are several use cases where it would be beneficial to allow easy creation of new context levels in plugins, for example Programs and Certifications. Another example would a creation of cohort contexts.
In all use cases the main point is to allow delegation of management permissions at a more granular level than course category, for example assigning a role for adding and removing cohort members for one particular cohort without the need for a dedicated course category.
Implementation
All context level class were moved into \core\context namespace. To maintain backwards compatibility the old names were aliased in accesslib.php file, it was not done via standard core_component class renaming because the aliases will be kept for a long time without deprecation. I would not be reasonable to search/replace the whole codebase and all plugins now.
Instead of hardcoding the list of available context levels in code there is a new file db/contexts.php which defines what context level classes are available in Moodle. This way plugins may add custom contexts without any kind of core modification while keeping similar performance.
There are several new methods in context levels that allow new context levels to alter settings for default roles that are created during installation, another aim is to improve support for custom levels in permissions UI:
- context::get_compatible_role_archetypes()
- context::get_possible_parent_levels()
- context::get_instance_table()
- context::get_behat_reference_columns()
Changes for end users
When importing data from external sources and in web services, numeric values of context levels can now be used instead of short context level names.
Changes for developers
Normal code should not depend on actual PHP class names of context class, developers should always use numbers to identify context levels.
When dealing with external level identifiers developers should use new \core\context_helper::parse_external_level() method, which accepts both old short names and numeric context level values.
I have asked other devs if they like this proposal at https://moodle.org/mod/forum/discuss.php?d=435307
- blocks
-
MDL-74937 Create cohort context level
-
- Closed
-