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 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Module; 21 22use Fisharebest\Webtrees\Menu; 23use Fisharebest\Webtrees\Tree; 24 25/** 26 * Trait ModuleListTrait - default implementation of ModuleListInterface 27 */ 28trait ModuleListTrait 29{ 30 /** 31 * A main menu item for this list, or null if the list is empty. 32 * 33 * @param Tree $tree 34 * 35 * @return Menu|null 36 */ 37 public function listMenu(Tree $tree): ?Menu 38 { 39 if ($this->listIsEmpty($tree)) { 40 return null; 41 } 42 43 return new Menu( 44 $this->listTitle(), 45 $this->listUrl($tree), 46 $this->listMenuClass(), 47 $this->listUrlAttributes() 48 ); 49 } 50 51 /** 52 * CSS class for the menu. 53 * 54 * @return string 55 */ 56 public function listMenuClass(): string 57 { 58 return ''; 59 } 60 61 /** 62 * The title for a specific instance of this list. 63 * 64 * @return string 65 */ 66 public function listTitle(): string 67 { 68 return $this->title(); 69 } 70 71 /** 72 * The URL for a page showing list options. 73 * 74 * @param Tree $tree 75 * @param mixed[] $parameters 76 * 77 * @return string 78 */ 79 public function listUrl(Tree $tree, array $parameters = []): string 80 { 81 return route('module', [ 82 'module' => $this->name(), 83 'action' => 'List', 84 'tree' => $tree->name(), 85 ] + $parameters); 86 } 87 88 /** 89 * Attributes for the URL. 90 * 91 * @return string[] 92 */ 93 public function listUrlAttributes(): array 94 { 95 return ['rel' => 'nofollow']; 96 } 97 98 /** 99 * @param Tree $tree 100 * 101 * @return bool 102 */ 103 public function listIsEmpty(Tree $tree): bool 104 { 105 return false; 106 } 107} 108