1441 |
ariadna |
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 |
declare(strict_types=1);
|
|
|
18 |
|
|
|
19 |
namespace core_user\hook;
|
|
|
20 |
|
|
|
21 |
use core\attribute\{label, tags};
|
|
|
22 |
use core\lang_string;
|
|
|
23 |
use core\url;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Hook to allow callbacks to extend the default homepage options
|
|
|
27 |
*
|
|
|
28 |
* @package core_user
|
|
|
29 |
* @copyright 2024 Paul Holden <paulh@moodle.com>
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
#[label('Allows callbacks to extend the default homepage options')]
|
|
|
33 |
#[tags('user')]
|
|
|
34 |
final class extend_default_homepage {
|
|
|
35 |
|
|
|
36 |
/** @var array $options */
|
|
|
37 |
private array $options = [];
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Hook constructor
|
|
|
41 |
*
|
|
|
42 |
* @param bool $userpreference Whether this is being selected as a user preference
|
|
|
43 |
*/
|
|
|
44 |
public function __construct(
|
|
|
45 |
/** @var bool $userpreference Whether this is being selected as a user preference */
|
|
|
46 |
public readonly bool $userpreference = false,
|
|
|
47 |
) {
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* To be called by callback to add an option
|
|
|
52 |
*
|
|
|
53 |
* @param url $url URL that can be used as a site homepage. Must be a local URL.
|
|
|
54 |
* @param lang_string|string $title
|
|
|
55 |
*/
|
|
|
56 |
public function add_option(url $url, lang_string|string $title): void {
|
|
|
57 |
$this->options[$url->out_as_local_url()] = $title;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Returns all added options
|
|
|
62 |
*
|
|
|
63 |
* @return array
|
|
|
64 |
*/
|
|
|
65 |
public function get_options(): array {
|
|
|
66 |
return $this->options;
|
|
|
67 |
}
|
|
|
68 |
}
|