xref: /webtrees/app/Module/ThemeSelectModule.php (revision da83637ca6236094f5a00d6e54530cd25ac7aa0e)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program 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 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\Module;
17
18use Fisharebest\Webtrees\I18N;
19use Fisharebest\Webtrees\Theme;
20use Fisharebest\Webtrees\Tree;
21
22/**
23 * Class ThemeSelectModule
24 */
25class ThemeSelectModule extends AbstractModule implements ModuleBlockInterface
26{
27    /** {@inheritdoc} */
28    public function getTitle()
29    {
30        return /* I18N: Name of a module */
31            I18N::translate('Theme change');
32    }
33
34    /** {@inheritdoc} */
35    public function getDescription()
36    {
37        return /* I18N: Description of the “Theme change” module */
38            I18N::translate('An alternative way to select a new theme.');
39    }
40
41    /**
42     * Generate the HTML content of this block.
43     *
44     * @param Tree     $tree
45     * @param int      $block_id
46     * @param bool     $template
47     * @param string[] $cfg
48     *
49     * @return string
50     */
51    public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
52    {
53        $menu = Theme::theme()->menuThemes();
54
55        if ($menu) {
56            $content = '<ul class="nav text-justify">' . $menu->bootstrap4() . '</ul>';
57
58            if ($template) {
59                return view('modules/block-template', [
60                    'block'      => str_replace('_', '-', $this->getName()),
61                    'id'         => $block_id,
62                    'config_url' => '',
63                    'title'      => $this->getTitle(),
64                    'content'    => $content,
65                ]);
66            } else {
67                return $content;
68            }
69        } else {
70            return '';
71        }
72    }
73
74    /** {@inheritdoc} */
75    public function loadAjax(): bool
76    {
77        return false;
78    }
79
80    /** {@inheritdoc} */
81    public function isUserBlock(): bool
82    {
83        return true;
84    }
85
86    /** {@inheritdoc} */
87    public function isGedcomBlock(): bool
88    {
89        return true;
90    }
91
92    /**
93     * An HTML form to edit block settings
94     *
95     * @param Tree $tree
96     * @param int  $block_id
97     *
98     * @return void
99     */
100    public function configureBlock(Tree $tree, int $block_id)
101    {
102    }
103}
104