xref: /webtrees/app/Module/ThemeSelectModule.php (revision 26684e686fb5ab50ecb57e7e6c6a0a55852d2203)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 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 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Module;
19
20use Fisharebest\Webtrees\I18N;
21use Fisharebest\Webtrees\Theme;
22use Fisharebest\Webtrees\Tree;
23use Symfony\Component\HttpFoundation\Request;
24
25/**
26 * Class ThemeSelectModule
27 */
28class ThemeSelectModule extends AbstractModule implements ModuleInterface, ModuleBlockInterface
29{
30    use ModuleBlockTrait;
31
32    /**
33     * How should this module be labelled on tabs, menus, etc.?
34     *
35     * @return string
36     */
37    public function title(): string
38    {
39        /* I18N: Name of a module */
40        return I18N::translate('Theme change');
41    }
42
43    /**
44     * A sentence describing what this module does.
45     *
46     * @return string
47     */
48    public function description(): string
49    {
50        /* I18N: Description of the “Theme change” module */
51        return I18N::translate('An alternative way to select a new theme.');
52    }
53
54    /**
55     * Generate the HTML content of this block.
56     *
57     * @param Tree     $tree
58     * @param int      $block_id
59     * @param string   $ctype
60     * @param string[] $cfg
61     *
62     * @return string
63     */
64    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
65    {
66        $menu = Theme::theme()->menuThemes();
67
68        if ($menu) {
69            $content = '<ul class="nav text-justify">' . $menu->bootstrap4() . '</ul>';
70
71            if ($ctype !== '') {
72                return view('modules/block-template', [
73                    'block'      => str_replace('_', '-', $this->name()),
74                    'id'         => $block_id,
75                    'config_url' => '',
76                    'title'      => $this->title(),
77                    'content'    => $content,
78                ]);
79            }
80
81            return $content;
82        }
83
84        return '';
85    }
86
87    /** {@inheritdoc} */
88    public function loadAjax(): bool
89    {
90        return false;
91    }
92
93    /** {@inheritdoc} */
94    public function isUserBlock(): bool
95    {
96        return true;
97    }
98
99    /** {@inheritdoc} */
100    public function isGedcomBlock(): bool
101    {
102        return true;
103    }
104
105    /**
106     * Update the configuration for a block.
107     *
108     * @param Request $request
109     * @param int     $block_id
110     *
111     * @return void
112     */
113    public function saveBlockConfiguration(Request $request, int $block_id)
114    {
115    }
116
117    /**
118     * An HTML form to edit block settings
119     *
120     * @param Tree $tree
121     * @param int  $block_id
122     *
123     * @return void
124     */
125    public function editBlockConfiguration(Tree $tree, int $block_id)
126    {
127    }
128}
129