xref: /webtrees/app/Module/ThemeSelectModule.php (revision d239cb0bd52ae30e36592e8b68f180897a644140)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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 <https://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\Registry;
25use Fisharebest\Webtrees\Tree;
26use Illuminate\Support\Str;
27
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 array<string,string> $config
66     *
67     * @return string
68     */
69    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
70    {
71        $theme = Registry::container()->get(ModuleThemeInterface::class);
72        $menu  = $theme->menuThemes();
73
74        if ($menu instanceof Menu) {
75            $content = '<ul class="nav text-justify" role="menu">' . view('components/menu-item', ['menu' => $menu]) . '</ul>';
76
77            if ($context !== self::CONTEXT_EMBED) {
78                return view('modules/block-template', [
79                    'block'      => Str::kebab($this->name()),
80                    'id'         => $block_id,
81                    'config_url' => '',
82                    'title'      => $this->title(),
83                    'content'    => $content,
84                ]);
85            }
86
87            return $content;
88        }
89
90        return '';
91    }
92
93    /**
94     * Should this block load asynchronously using AJAX?
95     *
96     * Simple blocks are faster in-line, more complex ones can be loaded later.
97     *
98     * @return bool
99     */
100    public function loadAjax(): bool
101    {
102        return false;
103    }
104
105    /**
106     * Can this block be shown on the user’s home page?
107     *
108     * @return bool
109     */
110    public function isUserBlock(): bool
111    {
112        return true;
113    }
114
115    /**
116     * Can this block be shown on the tree’s home page?
117     *
118     * @return bool
119     */
120    public function isTreeBlock(): bool
121    {
122        return true;
123    }
124}
125