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