xref: /webtrees/app/Module/ThemeSelectModule.php (revision d70512ab02636ee884ef6d7907223ed02c754ff5)
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\Tree;
24use Illuminate\Support\Str;
25
26/**
27 * Class ThemeSelectModule
28 */
29class ThemeSelectModule extends AbstractModule implements ModuleBlockInterface
30{
31    use ModuleBlockTrait;
32
33    /**
34     * How should this module be identified in the control panel, etc.?
35     *
36     * @return string
37     */
38    public function title(): string
39    {
40        /* I18N: Name of a module */
41        return I18N::translate('Theme change');
42    }
43
44    /**
45     * A sentence describing what this module does.
46     *
47     * @return string
48     */
49    public function description(): string
50    {
51        /* I18N: Description of the “Theme change” module */
52        return I18N::translate('An alternative way to select a new theme.');
53    }
54
55    /**
56     * Generate the HTML content of this block.
57     *
58     * @param Tree     $tree
59     * @param int      $block_id
60     * @param string   $context
61     * @param string[] $config
62     *
63     * @return string
64     */
65    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
66    {
67        $menu = app(ModuleThemeInterface::class)->menuThemes();
68
69        if ($menu) {
70            $content = '<ul class="nav text-justify">' . $menu->bootstrap4() . '</ul>';
71
72            if ($context !== self::CONTEXT_EMBED) {
73                return view('modules/block-template', [
74                    'block'      => Str::kebab($this->name()),
75                    'id'         => $block_id,
76                    'config_url' => '',
77                    'title'      => $this->title(),
78                    'content'    => $content,
79                ]);
80            }
81
82            return $content;
83        }
84
85        return '';
86    }
87
88    /**
89     * Should this block load asynchronously using AJAX?
90     *
91     * Simple blocks are faster in-line, more complex ones can be loaded later.
92     *
93     * @return bool
94     */
95    public function loadAjax(): bool
96    {
97        return false;
98    }
99
100    /**
101     * Can this block be shown on the user’s home page?
102     *
103     * @return bool
104     */
105    public function isUserBlock(): bool
106    {
107        return true;
108    }
109
110    /**
111     * Can this block be shown on the tree’s home page?
112     *
113     * @return bool
114     */
115    public function isTreeBlock(): bool
116    {
117        return true;
118    }
119}
120