Skip to content

Commit

Permalink
Implement new hook callbacks #65
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl authored and brendanheywood committed Jun 5, 2024
1 parent 965a4cc commit 056dd03
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
46 changes: 46 additions & 0 deletions classes/hook_callbacks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_abconfig;

/**
* Hook callbacks for tool_abconfig.
*
* @package tool_abconfig
* @author Benjamin Walker ([email protected])
* @copyright 2024 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class hook_callbacks {

/**
* Runs before HTTP headers.
*
* @param \core\hook\output\before_http_headers $hook
*/
public static function before_http_headers(\core\hook\output\before_http_headers $hook): void {
tool_abconfig_execute_js('header');
}

/**
* Runs before HTTP footers.
*
* @param \core\hook\output\before_footer_html_generation $hook
*/
public static function before_footer_html_generation(\core\hook\output\before_footer_html_generation $hook): void {
tool_abconfig_execute_js('footer');
}
}
39 changes: 39 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Hook callbacks for tool_abconfig
*
* @package tool_abconfig
* @author Benjamin Walker ([email protected])
* @copyright 2024 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$callbacks = [
[
'hook' => \core\hook\output\before_http_headers::class,
'callback' => '\tool_abconfig\hook_callbacks::before_http_headers',
'priority' => 0,
],
[
'hook' => \core\hook\output\before_footer_html_generation::class,
'callback' => '\tool_abconfig\hook_callbacks::before_footer_html_generation',
'priority' => 0,
],
];
8 changes: 8 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function tool_abconfig_after_require_login() {

/**
* Before footer
*
* This is a legacy callback that is used for compatibility with older Moodle versions.
* Moodle 4.4+ will use tool_abconfig\hook_callbacks::before_footer_html_generation instead.
*
* @return void
*/
function tool_abconfig_before_footer() {
Expand All @@ -230,6 +234,10 @@ function tool_abconfig_before_footer() {

/**
* Before http headers
*
* This is a legacy callback that is used for compatibility with older Moodle versions.
* Moodle 4.4+ will use tool_abconfig\hook_callbacks::before_http_headers instead.
*
* @return void
*/
function tool_abconfig_before_http_headers() {
Expand Down
6 changes: 3 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022070600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022062201; // Same as version.
$plugin->version = 2024060400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2024060400; // Same as version.
$plugin->requires = 2014051217;
$plugin->supported = [38, 401]; // Available as of Moodle 3.8.0 or later.
$plugin->supported = [38, 404]; // Available as of Moodle 3.8.0 or later.
$plugin->component = "tool_abconfig";
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 056dd03

Please sign in to comment.