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