xref: /webtrees/app/Module/ThemeSelectModule.php (revision 3eae54c8a20b98985facfcff8d58c982338bbf85)
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 Illuminate\Support\Str;
23
24/**
25 * Class ThemeSelectModule
26 */
27class ThemeSelectModule extends AbstractModule implements ModuleBlockInterface
28{
29    use ModuleBlockTrait;
30
31    /**
32     * How should this module be identified in the control panel, 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   $context
59     * @param string[] $config
60     *
61     * @return string
62     */
63    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
64    {
65        $menu = app(ModuleThemeInterface::class)->menuThemes();
66
67        if ($menu) {
68            $content = '<ul class="nav text-justify">' . $menu->bootstrap4() . '</ul>';
69
70            if ($context !== self::CONTEXT_EMBED) {
71                return view('modules/block-template', [
72                    'block'      => Str::kebab($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    /**
87     * Should this block load asynchronously using AJAX?
88     *
89     * Simple blocks are faster in-line, more complex ones can be loaded later.
90     *
91     * @return bool
92     */
93    public function loadAjax(): bool
94    {
95        return false;
96    }
97
98    /**
99     * Can this block be shown on the user’s home page?
100     *
101     * @return bool
102     */
103    public function isUserBlock(): bool
104    {
105        return true;
106    }
107
108    /**
109     * Can this block be shown on the tree’s home page?
110     *
111     * @return bool
112     */
113    public function isTreeBlock(): bool
114    {
115        return true;
116    }
117}
118