Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-74936

Move context classes to namespace

XMLWordPrintable

    • MOODLE_401_STABLE
    • MOODLE_402_STABLE
    • Hide
      1. All code changes should be covered by phpunit and behat - old test were intentionally left behind unmodified to prove backwards compatibloty, new tests were added to test new class names and refactoring
      2. There should not be any visible UI changes, so manual regression testing should be done only for role management area in /admin/roles/*.
      3. The preexisting unsupported $CFG->custom_context_classes setting should be less broken now - I can create a documentation update and some examples if this gets accepted.
         

      To integrators: I have kept the names of static member variables with in context class intentionally, I do not think it would be appropriate to break backwards API compatibility only because of current Moodle coding style rules.

      Show
      All code changes should be covered by phpunit and behat - old test were intentionally left behind unmodified to prove backwards compatibloty, new tests were added to test new class names and refactoring There should not be any visible UI changes, so manual regression testing should be done only for role management area in /admin/roles/*. The preexisting unsupported $CFG->custom_context_classes setting should be less broken now - I can create a documentation update and some examples if this gets accepted.   To integrators: I have kept the names of static member variables with in context class intentionally, I do not think it would be appropriate to break backwards API compatibility only because of current Moodle coding style rules.

      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:

      1. context::get_compatible_role_archetypes()
      2. context::get_possible_parent_levels()
      3. context::get_instance_table()
      4. 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

            skodak Petr Skoda
            skodak Petr Skoda
            Farhan Karmali Farhan Karmali
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days
                2d

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.