From 96e2caeaa2bb9b4895a7166c1a3c345086a811ff Mon Sep 17 00:00:00 2001 From: sam marshall Date: Wed, 11 May 2022 15:10:43 +0100 Subject: [PATCH] MDL-74733 core_navigation: Secondary nav in plugins, change namespace Secondary nav previously had to be in my_plugin\local\views\secondary; this location continues to work but is deprecated. The new location is my_plugin\navigation\views\secondary. --- .../{local => navigation}/views/secondary.php | 2 +- lib/blocklib.php | 12 ++++++++++-- lib/pagelib.php | 11 ++++++++++- lib/upgrade.txt | 3 +++ .../{local => navigation}/views/secondary.php | 2 +- .../{local => navigation}/views/secondary.php | 2 +- .../{local => navigation}/views/secondary.php | 2 +- .../{local => navigation}/views/secondary.php | 2 +- .../{local => navigation}/views/secondary.php | 2 +- 9 files changed, 29 insertions(+), 9 deletions(-) rename blocks/classes/{local => navigation}/views/secondary.php (96%) rename mod/assign/classes/{local => navigation}/views/secondary.php (97%) rename mod/feedback/classes/{local => navigation}/views/secondary.php (98%) rename mod/glossary/classes/{local => navigation}/views/secondary.php (97%) rename mod/label/classes/{local => navigation}/views/secondary.php (98%) rename mod/quiz/classes/{local => navigation}/views/secondary.php (98%) diff --git a/blocks/classes/local/views/secondary.php b/blocks/classes/navigation/views/secondary.php similarity index 96% rename from blocks/classes/local/views/secondary.php rename to blocks/classes/navigation/views/secondary.php index c23e857a5f7..43acdadf8c8 100644 --- a/blocks/classes/local/views/secondary.php +++ b/blocks/classes/navigation/views/secondary.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace core_block\local\views; +namespace core_block\navigation\views; /** * Class secondary diff --git a/lib/blocklib.php b/lib/blocklib.php index 9c4f2badbfc..f6fc929087d 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1684,12 +1684,20 @@ class block_manager { * Convenience function to check whether a block is implementing a secondary nav class and return it * initialised to the calling function * + * @todo MDL-74939 Remove support for old 'local\views\secondary' class location * @param block_base $block * @return \core\navigation\views\secondary */ protected function get_secondarynav(block_base $block): \core\navigation\views\secondary { - $class = "core_block\\local\\views\\secondary"; - if (class_exists("block_{$block->name()}\\local\\views\\secondary")) { + $class = "core_block\\navigation\\views\\secondary"; + if (class_exists("block_{$block->name()}\\navigation\\views\\secondary")) { + $class = "block_{$block->name()}\\navigation\\views\\secondary"; + } else if (class_exists("block_{$block->name()}\\local\\views\\secondary")) { + // For backwards compatibility, support the old location for this class (it was in a + // 'local' namespace which shouldn't be used for core APIs). + debugging("The class block_{$block->name()}\\local\\views\\secondary uses a deprecated " . + "namespace. Please move it to block_{$block->name()}\\navigation\\views\\secondary.", + DEBUG_DEVELOPER); $class = "block_{$block->name()}\\local\\views\\secondary"; } $secondarynav = new $class($this->page); diff --git a/lib/pagelib.php b/lib/pagelib.php index 26cc6e5f86d..04bba10aff9 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -867,13 +867,22 @@ class moodle_page { /** * Returns the secondary navigation object + * + * @todo MDL-74939 Remove support for old 'local\views\secondary' class location * @return secondary */ protected function magic_get_secondarynav() { if ($this->_secondarynav === null) { $class = 'core\navigation\views\secondary'; // Try and load a custom class first. - if (class_exists("mod_{$this->activityname}\\local\\views\\secondary")) { + if (class_exists("mod_{$this->activityname}\\navigation\\views\\secondary")) { + $class = "mod_{$this->activityname}\\navigation\\views\\secondary"; + } else if (class_exists("mod_{$this->activityname}\\local\\views\\secondary")) { + // For backwards compatibility, support the old location for this class (it was in a + // 'local' namespace which shouldn't be used for core APIs). + debugging("The class mod_{$this->activityname}}\\local\\views\\secondary uses a deprecated " . + "namespace. Please move it to mod_{$this->activityname}\\navigation\\views\\secondary.", + DEBUG_DEVELOPER); $class = "mod_{$this->activityname}\\local\\views\\secondary"; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index f4fcd3a0298..00faa3f45f5 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -11,6 +11,9 @@ information provided here is intended especially for developers. * For performance reasons, sql_reader interface has a new function get_events_select_exists() which determines whether an event exists with the given criteria (see MDL-72723 for details). - Breaking: 3rd party log readers implementing interface sql_reader will need to implement get_events_select_exists() +* For plugins that override secondary navigation, the namespace for the custom secondary navigation class has + changed. It was (for example) mod_mymodule\local\views\secondary but is now + mod_mymodule\navigation\views\secondary. The old location will continue to work, but is deprecated. === 4.0 === diff --git a/mod/assign/classes/local/views/secondary.php b/mod/assign/classes/navigation/views/secondary.php similarity index 97% rename from mod/assign/classes/local/views/secondary.php rename to mod/assign/classes/navigation/views/secondary.php index 4b490964c15..e7a83770c10 100644 --- a/mod/assign/classes/local/views/secondary.php +++ b/mod/assign/classes/navigation/views/secondary.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_assign\local\views; +namespace mod_assign\navigation\views; use core\navigation\views\secondary as core_secondary; diff --git a/mod/feedback/classes/local/views/secondary.php b/mod/feedback/classes/navigation/views/secondary.php similarity index 98% rename from mod/feedback/classes/local/views/secondary.php rename to mod/feedback/classes/navigation/views/secondary.php index 2aaa9d39eeb..e61d5aef411 100644 --- a/mod/feedback/classes/local/views/secondary.php +++ b/mod/feedback/classes/navigation/views/secondary.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_feedback\local\views; +namespace mod_feedback\navigation\views; use core\navigation\views\secondary as core_secondary; use settings_navigation; diff --git a/mod/glossary/classes/local/views/secondary.php b/mod/glossary/classes/navigation/views/secondary.php similarity index 97% rename from mod/glossary/classes/local/views/secondary.php rename to mod/glossary/classes/navigation/views/secondary.php index 83e2edd46e8..0c1b7fec585 100644 --- a/mod/glossary/classes/local/views/secondary.php +++ b/mod/glossary/classes/navigation/views/secondary.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_glossary\local\views; +namespace mod_glossary\navigation\views; use core\navigation\views\secondary as core_secondary; diff --git a/mod/label/classes/local/views/secondary.php b/mod/label/classes/navigation/views/secondary.php similarity index 98% rename from mod/label/classes/local/views/secondary.php rename to mod/label/classes/navigation/views/secondary.php index bba9e330302..64be842fd86 100644 --- a/mod/label/classes/local/views/secondary.php +++ b/mod/label/classes/navigation/views/secondary.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_label\local\views; +namespace mod_label\navigation\views; use core\navigation\views\secondary as core_secondary; use settings_navigation; diff --git a/mod/quiz/classes/local/views/secondary.php b/mod/quiz/classes/navigation/views/secondary.php similarity index 98% rename from mod/quiz/classes/local/views/secondary.php rename to mod/quiz/classes/navigation/views/secondary.php index e9be56666a4..89a6d3f17a9 100644 --- a/mod/quiz/classes/local/views/secondary.php +++ b/mod/quiz/classes/navigation/views/secondary.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -namespace mod_quiz\local\views; +namespace mod_quiz\navigation\views; use core\navigation\views\secondary as core_secondary;