xref: /webtrees/app/Module/ThemeSelectModule.php (revision 94026f200c17dcfccf296678dc90ea88b14f6246)
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 ModuleBlockInterface
29{
30    /** {@inheritdoc} */
31    public function getTitle(): string
32    {
33        /* I18N: Name of a module */
34        return I18N::translate('Theme change');
35    }
36
37    /** {@inheritdoc} */
38    public function getDescription(): string
39    {
40        /* I18N: Description of the “Theme change” module */
41        return I18N::translate('An alternative way to select a new theme.');
42    }
43
44    /**
45     * Generate the HTML content of this block.
46     *
47     * @param Tree     $tree
48     * @param int      $block_id
49     * @param string   $ctype
50     * @param string[] $cfg
51     *
52     * @return string
53     */
54    public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
55    {
56        $menu = Theme::theme()->menuThemes();
57
58        if ($menu) {
59            $content = '<ul class="nav text-justify">' . $menu->bootstrap4() . '</ul>';
60
61            if ($ctype !== '') {
62                return view('modules/block-template', [
63                    'block'      => str_replace('_', '-', $this->getName()),
64                    'id'         => $block_id,
65                    'config_url' => '',
66                    'title'      => $this->getTitle(),
67                    'content'    => $content,
68                ]);
69            }
70
71            return $content;
72        }
73
74        return '';
75    }
76
77    /** {@inheritdoc} */
78    public function loadAjax(): bool
79    {
80        return false;
81    }
82
83    /** {@inheritdoc} */
84    public function isUserBlock(): bool
85    {
86        return true;
87    }
88
89    /** {@inheritdoc} */
90    public function isGedcomBlock(): bool
91    {
92        return true;
93    }
94
95    /**
96     * Update the configuration for a block.
97     *
98     * @param Request $request
99     * @param int     $block_id
100     *
101     * @return void
102     */
103    public function saveBlockConfiguration(Request $request, int $block_id)
104    {
105    }
106
107    /**
108     * An HTML form to edit block settings
109     *
110     * @param Tree $tree
111     * @param int  $block_id
112     *
113     * @return void
114     */
115    public function editBlockConfiguration(Tree $tree, int $block_id)
116    {
117    }
118}
119