18c2e8227SGreg Roach<?php 23976b470SGreg Roach 38c2e8227SGreg Roach/** 48c2e8227SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 98c2e8227SGreg Roach * (at your option) any later version. 108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138c2e8227SGreg Roach * GNU General Public License for more details. 148c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 168c2e8227SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 2176692c8bSGreg Roach 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 23f78837dcSGreg Roachuse Fisharebest\Webtrees\Menu; 24*d35568b4SGreg Roachuse Fisharebest\Webtrees\Registry; 25e490cd80SGreg Roachuse Fisharebest\Webtrees\Tree; 261e7a7a28SGreg Roachuse Illuminate\Support\Str; 278c2e8227SGreg Roach 28f78837dcSGreg Roachuse function view; 29f78837dcSGreg Roach 308c2e8227SGreg Roach/** 318c2e8227SGreg Roach * Class ThemeSelectModule 328c2e8227SGreg Roach */ 3337eb8894SGreg Roachclass ThemeSelectModule extends AbstractModule implements ModuleBlockInterface 34c1010edaSGreg Roach{ 3549a243cbSGreg Roach use ModuleBlockTrait; 3649a243cbSGreg Roach 37961ec755SGreg Roach /** 380cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 39961ec755SGreg Roach * 40961ec755SGreg Roach * @return string 41961ec755SGreg Roach */ 4249a243cbSGreg Roach public function title(): string 43c1010edaSGreg Roach { 44bbb76c12SGreg Roach /* I18N: Name of a module */ 45bbb76c12SGreg Roach return I18N::translate('Theme change'); 468c2e8227SGreg Roach } 478c2e8227SGreg 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 593caaa4d2SGreg Roach * @param string $context 6076d39c55SGreg Roach * @param array<string,string> $config 6176692c8bSGreg Roach * 6276692c8bSGreg Roach * @return string 6376692c8bSGreg Roach */ 643caaa4d2SGreg Roach public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 65c1010edaSGreg Roach { 66*d35568b4SGreg Roach $theme = Registry::container()->get(ModuleThemeInterface::class); 67b55cbc6bSGreg Roach $menu = $theme->menuThemes(); 688c2e8227SGreg Roach 69f78837dcSGreg Roach if ($menu instanceof Menu) { 70f78837dcSGreg Roach $content = '<ul class="nav text-justify" role="menu">' . view('components/menu-item', ['menu' => $menu]) . '</ul>'; 718c2e8227SGreg Roach 723caaa4d2SGreg Roach if ($context !== self::CONTEXT_EMBED) { 73147e99aaSGreg Roach return view('modules/block-template', [ 741e7a7a28SGreg Roach 'block' => Str::kebab($this->name()), 759c6524dcSGreg Roach 'id' => $block_id, 769c6524dcSGreg Roach 'config_url' => '', 7749a243cbSGreg Roach 'title' => $this->title(), 789c6524dcSGreg Roach 'content' => $content, 799c6524dcSGreg Roach ]); 80b2ce94c6SRico Sonntag } 81b2ce94c6SRico Sonntag 828c2e8227SGreg Roach return $content; 838c2e8227SGreg Roach } 84b2ce94c6SRico Sonntag 858c2e8227SGreg Roach return ''; 868c2e8227SGreg Roach } 878c2e8227SGreg Roach 883caaa4d2SGreg Roach /** 893caaa4d2SGreg Roach * Should this block load asynchronously using AJAX? 903caaa4d2SGreg Roach * 913caaa4d2SGreg Roach * Simple blocks are faster in-line, more complex ones can be loaded later. 923caaa4d2SGreg Roach * 933caaa4d2SGreg Roach * @return bool 943caaa4d2SGreg Roach */ 95c1010edaSGreg Roach public function loadAjax(): bool 96c1010edaSGreg Roach { 978c2e8227SGreg Roach return false; 988c2e8227SGreg Roach } 998c2e8227SGreg Roach 1003caaa4d2SGreg Roach /** 1013caaa4d2SGreg Roach * Can this block be shown on the user’s home page? 1023caaa4d2SGreg Roach * 1033caaa4d2SGreg Roach * @return bool 1043caaa4d2SGreg Roach */ 105c1010edaSGreg Roach public function isUserBlock(): bool 106c1010edaSGreg Roach { 1078c2e8227SGreg Roach return true; 1088c2e8227SGreg Roach } 1098c2e8227SGreg Roach 1103caaa4d2SGreg Roach /** 1113caaa4d2SGreg Roach * Can this block be shown on the tree’s home page? 1123caaa4d2SGreg Roach * 1133caaa4d2SGreg Roach * @return bool 1143caaa4d2SGreg Roach */ 11563276d8fSGreg Roach public function isTreeBlock(): bool 116c1010edaSGreg Roach { 1178c2e8227SGreg Roach return true; 1188c2e8227SGreg Roach } 1198c2e8227SGreg Roach} 120