xref: /webtrees/app/Module/ThemeSelectModule.php (revision 00b1984e374faddab4698e73088f0c964e529b65)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\I18N;
23use Fisharebest\Webtrees\Menu;
24use Fisharebest\Webtrees\Tree;
25use Illuminate\Support\Str;
26
27use function app;
28use function view;
29
30/**
31 * Class ThemeSelectModule
32 */
33class ThemeSelectModule extends AbstractModule implements ModuleBlockInterface
34{
35    use ModuleBlockTrait;
36
37    /**
38     * How should this module be identified in the control panel, etc.?
39     *
40     * @return string
41     */
42    public function title(): string
43    {
44        /* I18N: Name of a module */
45        return I18N::translate('Theme change');
46    }
47
48    /**
49     * A sentence describing what this module does.
50     *
51     * @return string
52     */
53    public function description(): string
54    {
55        /* I18N: Description of the “Theme change” module */
56        return I18N::translate('An alternative way to select a new theme.');
57    }
58
59    /**
60     * Generate the HTML content of this block.
61     *
62     * @param Tree     $tree
63     * @param int      $block_id
64     * @param string   $context
65     * @param string[] $config
66     *
67     * @return string
68     */
69    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
70    {
71        $menu = app(ModuleThemeInterface::class)->menuThemes();
72
73        if ($menu instanceof Menu) {
74            $content = '<ul class="nav text-justify" role="menu">' . view('components/menu-item', ['menu' => $menu]) . '</ul>';
75
76            if ($context !== self::CONTEXT_EMBED) {
77                return view('modules/block-template', [
78                    'block'      => Str::kebab($this->name()),
79                    'id'         => $block_id,
80                    'config_url' => '',
81                    'title'      => $this->title(),
82                    'content'    => $content,
83                ]);
84            }
85
86            return $content;
87        }
88
89        return '';
90    }
91
92    /**
93     * Should this block load asynchronously using AJAX?
94     *
95     * Simple blocks are faster in-line, more complex ones can be loaded later.
96     *
97     * @return bool
98     */
99    public function loadAjax(): bool
100    {
101        return false;
102    }
103
104    /**
105     * Can this block be shown on the user’s home page?
106     *
107     * @return bool
108     */
109    public function isUserBlock(): bool
110    {
111        return true;
112    }
113
114    /**
115     * Can this block be shown on the tree’s home page?
116     *
117     * @return bool
118     */
119    public function isTreeBlock(): bool
120    {
121        return true;
122    }
123}
124