xref: /webtrees/app/Module/ThemeSelectModule.php (revision 3caaa4d28e5aa6cc52c831b60066ebdc346fcd50)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
88c2e8227SGreg Roach * (at your option) any later version.
98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128c2e8227SGreg Roach * GNU General Public License for more details.
138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
158c2e8227SGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1976692c8bSGreg Roach
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
21e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree;
221e7a7a28SGreg Roachuse Illuminate\Support\Str;
236ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
248c2e8227SGreg Roach
258c2e8227SGreg Roach/**
268c2e8227SGreg Roach * Class ThemeSelectModule
278c2e8227SGreg Roach */
2837eb8894SGreg Roachclass ThemeSelectModule extends AbstractModule implements ModuleBlockInterface
29c1010edaSGreg Roach{
3049a243cbSGreg Roach    use ModuleBlockTrait;
3149a243cbSGreg Roach
32961ec755SGreg Roach    /**
330cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
34961ec755SGreg Roach     *
35961ec755SGreg Roach     * @return string
36961ec755SGreg Roach     */
3749a243cbSGreg Roach    public function title(): string
38c1010edaSGreg Roach    {
39bbb76c12SGreg Roach        /* I18N: Name of a module */
40bbb76c12SGreg Roach        return I18N::translate('Theme change');
418c2e8227SGreg Roach    }
428c2e8227SGreg Roach
43961ec755SGreg Roach    /**
44961ec755SGreg Roach     * A sentence describing what this module does.
45961ec755SGreg Roach     *
46961ec755SGreg Roach     * @return string
47961ec755SGreg Roach     */
4849a243cbSGreg Roach    public function description(): string
49c1010edaSGreg Roach    {
50bbb76c12SGreg Roach        /* I18N: Description of the “Theme change” module */
51bbb76c12SGreg Roach        return I18N::translate('An alternative way to select a new theme.');
528c2e8227SGreg Roach    }
538c2e8227SGreg Roach
5476692c8bSGreg Roach    /**
5576692c8bSGreg Roach     * Generate the HTML content of this block.
5676692c8bSGreg Roach     *
57e490cd80SGreg Roach     * @param Tree     $tree
5876692c8bSGreg Roach     * @param int      $block_id
59*3caaa4d2SGreg Roach     * @param string   $context
60*3caaa4d2SGreg Roach     * @param string[] $config
6176692c8bSGreg Roach     *
6276692c8bSGreg Roach     * @return string
6376692c8bSGreg Roach     */
64*3caaa4d2SGreg Roach    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string
65c1010edaSGreg Roach    {
66cab242e7SGreg Roach        $menu = app(ModuleThemeInterface::class)->menuThemes();
678c2e8227SGreg Roach
688c2e8227SGreg Roach        if ($menu) {
6915d603e7SGreg Roach            $content = '<ul class="nav text-justify">' . $menu->bootstrap4() . '</ul>';
708c2e8227SGreg Roach
71*3caaa4d2SGreg Roach            if ($context !== self::CONTEXT_EMBED) {
72147e99aaSGreg Roach                return view('modules/block-template', [
731e7a7a28SGreg Roach                    'block'      => Str::kebab($this->name()),
749c6524dcSGreg Roach                    'id'         => $block_id,
759c6524dcSGreg Roach                    'config_url' => '',
7649a243cbSGreg Roach                    'title'      => $this->title(),
779c6524dcSGreg Roach                    'content'    => $content,
789c6524dcSGreg Roach                ]);
79b2ce94c6SRico Sonntag            }
80b2ce94c6SRico Sonntag
818c2e8227SGreg Roach            return $content;
828c2e8227SGreg Roach        }
83b2ce94c6SRico Sonntag
848c2e8227SGreg Roach        return '';
858c2e8227SGreg Roach    }
868c2e8227SGreg Roach
87*3caaa4d2SGreg Roach    /**
88*3caaa4d2SGreg Roach     * Should this block load asynchronously using AJAX?
89*3caaa4d2SGreg Roach     *
90*3caaa4d2SGreg Roach     * Simple blocks are faster in-line, more complex ones can be loaded later.
91*3caaa4d2SGreg Roach     *
92*3caaa4d2SGreg Roach     * @return bool
93*3caaa4d2SGreg Roach     */
94c1010edaSGreg Roach    public function loadAjax(): bool
95c1010edaSGreg Roach    {
968c2e8227SGreg Roach        return false;
978c2e8227SGreg Roach    }
988c2e8227SGreg Roach
99*3caaa4d2SGreg Roach    /**
100*3caaa4d2SGreg Roach     * Can this block be shown on the user’s home page?
101*3caaa4d2SGreg Roach     *
102*3caaa4d2SGreg Roach     * @return bool
103*3caaa4d2SGreg Roach     */
104c1010edaSGreg Roach    public function isUserBlock(): bool
105c1010edaSGreg Roach    {
1068c2e8227SGreg Roach        return true;
1078c2e8227SGreg Roach    }
1088c2e8227SGreg Roach
109*3caaa4d2SGreg Roach    /**
110*3caaa4d2SGreg Roach     * Can this block be shown on the tree’s home page?
111*3caaa4d2SGreg Roach     *
112*3caaa4d2SGreg Roach     * @return bool
113*3caaa4d2SGreg Roach     */
11463276d8fSGreg Roach    public function isTreeBlock(): bool
115c1010edaSGreg Roach    {
1168c2e8227SGreg Roach        return true;
1178c2e8227SGreg Roach    }
1188c2e8227SGreg Roach}
119