Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core\hook\output;
18
 
19
use renderer_base;
20
 
21
/**
22
 * Hook to allow subscribers to add HTML content to the footer.
23
 *
24
 * @package    core
25
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
#[\core\attribute\tags('output')]
29
#[\core\attribute\label('Allows plugins to add any elements to the page footer.')]
30
#[\core\attribute\hook\replaces_callbacks('standard_footer_html')]
31
final class before_standard_footer_html_generation {
32
    /**
33
     * Hook to allow subscribers to add HTML content before the footer.
34
     *
35
     * @param renderer_base $renderer
36
     * @param string $output Initial output
37
     */
38
    public function __construct(
39
        /** @var renderer_base The page renderer object */
40
        public readonly renderer_base $renderer,
41
        /** @var string The collected output */
42
        private string $output = '',
43
    ) {
44
    }
45
 
46
    /**
47
     * Plugins implementing callback can add any HTML to the top of the body.
48
     *
49
     * Must be a string containing valid html head content.
50
     *
51
     * @param null|string $output
52
     */
53
    public function add_html(?string $output): void {
54
        if ($output) {
55
            $this->output .= $output;
56
        }
57
    }
58
 
59
    /**
60
     * Returns all HTML added by the plugins
61
     *
62
     * @return string
63
     */
64
    public function get_output(): string {
65
        return $this->output;
66
    }
67
 
68
    /**
69
     * Process legacy callbacks.
70
     *
71
     * Legacy callback 'standard_footer_html' is deprecated since Moodle 4.4
72
     */
73
    public function process_legacy_callbacks(): void {
74
        // Give plugins an opportunity to add any footer elements.
75
        // The callback must always return a string containing valid html footer content.
76
        $pluginswithfunction = get_plugins_with_function(function: 'standard_footer_html', migratedtohook: true);
77
        foreach ($pluginswithfunction as $plugins) {
78
            foreach ($plugins as $function) {
79
                $this->add_html($function());
80
            }
81
        }
82
    }
83
}