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 public function description(): string 49 { 50 /* I18N: Description of the “Theme change” module */ 51 return I18N::translate('An alternative way to select a new theme.'); 52 } 53 54 /** 55 * Generate the HTML content of this block. 56 * 57 * @param Tree $tree 58 * @param int $block_id 59 * @param string $context 60 * @param array<string,string> $config 61 * 62 * @return string 63 */ 64 public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 65 { 66 $theme = Registry::container()->get(ModuleThemeInterface::class); 67 $menu = $theme->menuThemes(); 68 69 if ($menu instanceof Menu) { 70 $content = '<ul class="nav text-justify" role="menu">' . view('components/menu-item', ['menu' => $menu]) . '</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