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