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