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