|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +namespace local_datacleaner; |
| 18 | +/** |
| 19 | + * The action button in config page. |
| 20 | + * |
| 21 | + * @package local_datacleaner |
| 22 | + * @author Dustin Huynh <[email protected]> |
| 23 | + * @copyright 2025, Catalyst IT |
| 24 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 25 | + */ |
| 26 | +class admin_setting_configbutton extends \admin_setting { |
| 27 | + |
| 28 | + /** @var string Button label */ |
| 29 | + protected $label; |
| 30 | + /** @var string Button href */ |
| 31 | + protected $href; |
| 32 | + |
| 33 | + /** |
| 34 | + * A button element |
| 35 | + * |
| 36 | + * @param string $name unique ascii name. |
| 37 | + * @param string $visiblename heading |
| 38 | + * @param string $description description of what the button does |
| 39 | + * @param string $label what is written on the button |
| 40 | + * @param string $href the URL directed to on click |
| 41 | + */ |
| 42 | + public function __construct($name, $visiblename, $description, $label, $href) { |
| 43 | + $this->nosave = true; |
| 44 | + $this->label = $label; |
| 45 | + $this->href = $href; |
| 46 | + parent::__construct($name, $visiblename, $description, ''); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Always returns true |
| 51 | + * @return bool Always returns true |
| 52 | + */ |
| 53 | + public function get_setting() { |
| 54 | + return true; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Never write settings |
| 59 | + * @return string Always returns an empty string |
| 60 | + */ |
| 61 | + public function write_setting($data) { |
| 62 | + return ''; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Returns an HTML string |
| 67 | + * @param mixed $data |
| 68 | + * @param string $query |
| 69 | + * @return string Returns an HTML string |
| 70 | + */ |
| 71 | + public function output_html($data, $query = '') { |
| 72 | + $button = \html_writer::tag('a', |
| 73 | + $this->label, |
| 74 | + [ |
| 75 | + 'href' => $this->href, |
| 76 | + 'style' => 'margin-top: 10px; display: inline-block;', |
| 77 | + ] |
| 78 | + ); |
| 79 | + return format_admin_setting($this, $this->visiblename, $button, $this->description); |
| 80 | + } |
| 81 | +} |
0 commit comments