Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
namespace mod_subsection\local\callbacks;
18
 
19
use core_course\hook\before_activitychooserbutton_exported;
20
use action_link;
21
use moodle_url;
22
use mod_subsection\permission;
23
use pix_icon;
24
use section_info;
25
 
26
/**
27
 * Class before activity choooser button export handler.
28
 *
29
 * @package    mod_subsection
30
 * @copyright  2024 Mikel Martín <mikel@moodle.com>
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class before_activitychooserbutton_exported_handler {
34
    /**
35
     * Handle the activity chooser button extra items addition.
36
     *
37
     * @param before_activitychooserbutton_exported $hook
38
     */
39
    public static function callback(before_activitychooserbutton_exported $hook): void {
40
        /** @var section_info $section */
41
        $section = $hook->get_section();
42
 
43
        if (!permission::can_add_subsection($section)) {
44
            return;
45
        }
46
 
47
        $attributes = [
48
            'class' => 'dropdown-item',
49
            'data-action' => 'newModule',
50
            'data-modname' => 'subsection',
51
            'data-sectionnum' => $section->sectionnum,
52
            'data-sectionid' => $section->id,
53
        ];
54
        if ($hook->get_cm()) {
55
            $attributes['data-beforemod'] = $hook->get_cm()->id;
56
        }
57
 
58
        $hook->get_activitychooserbutton()->add_action_link(new action_link(
59
            new moodle_url('#'),
60
            get_string('modulename', 'mod_subsection'),
61
            null,
62
            $attributes,
63
            new pix_icon('subsection', '', 'mod_subsection')
64
        ));
65
    }
66
}