167992b6aSRichard Cissee<?php 23976b470SGreg Roach 367992b6aSRichard Cissee/** 467992b6aSRichard Cissee * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 667992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify 767992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by 867992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or 967992b6aSRichard Cissee * (at your option) any later version. 1067992b6aSRichard Cissee * This program is distributed in the hope that it will be useful, 1167992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of 1267992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1367992b6aSRichard Cissee * GNU General Public License for more details. 1467992b6aSRichard Cissee * 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/>. 1667992b6aSRichard Cissee */ 17fcfa147eSGreg Roach 1867992b6aSRichard Cisseedeclare(strict_types=1); 1967992b6aSRichard Cissee 2067992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module; 2167992b6aSRichard Cissee 2267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Menu; 2367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Tree; 2467992b6aSRichard Cissee 2567992b6aSRichard Cissee/** 2667992b6aSRichard Cissee * Trait ModuleListTrait - default implementation of ModuleListInterface 2767992b6aSRichard Cissee */ 2867992b6aSRichard Cisseetrait ModuleListTrait 2967992b6aSRichard Cissee{ 3067992b6aSRichard Cissee /** 31bfed30e4SGreg Roach * A unique internal name for this module (based on the installation folder). 32bfed30e4SGreg Roach * 33bfed30e4SGreg Roach * @return string 34bfed30e4SGreg Roach */ 35bfed30e4SGreg Roach abstract public function name(): string; 36bfed30e4SGreg Roach 37bfed30e4SGreg Roach /** 38bfed30e4SGreg Roach * How should this module be identified in the control panel, etc.? 39bfed30e4SGreg Roach * 40bfed30e4SGreg Roach * @return string 41bfed30e4SGreg Roach */ 42bfed30e4SGreg Roach abstract public function title(): string; 43bfed30e4SGreg Roach 44bfed30e4SGreg Roach /** 4567992b6aSRichard Cissee * A main menu item for this list, or null if the list is empty. 4667992b6aSRichard Cissee * 4767992b6aSRichard Cissee * @param Tree $tree 4867992b6aSRichard Cissee * 4967992b6aSRichard Cissee * @return Menu|null 5067992b6aSRichard Cissee */ 51*1ff45046SGreg Roach public function listMenu(Tree $tree): Menu|null 5267992b6aSRichard Cissee { 5367992b6aSRichard Cissee if ($this->listIsEmpty($tree)) { 5467992b6aSRichard Cissee return null; 5567992b6aSRichard Cissee } 5667992b6aSRichard Cissee 5767992b6aSRichard Cissee return new Menu( 5855f111b1SRichard Cissée $this->listTitle(), 5967992b6aSRichard Cissee $this->listUrl($tree), 6067992b6aSRichard Cissee $this->listMenuClass(), 6167992b6aSRichard Cissee $this->listUrlAttributes() 6267992b6aSRichard Cissee ); 6367992b6aSRichard Cissee } 6467992b6aSRichard Cissee 6567992b6aSRichard Cissee /** 6667992b6aSRichard Cissee * CSS class for the menu. 6767992b6aSRichard Cissee * 6867992b6aSRichard Cissee * @return string 6967992b6aSRichard Cissee */ 7067992b6aSRichard Cissee public function listMenuClass(): string 7167992b6aSRichard Cissee { 7267992b6aSRichard Cissee return ''; 7367992b6aSRichard Cissee } 7467992b6aSRichard Cissee 7567992b6aSRichard Cissee /** 7667992b6aSRichard Cissee * The title for a specific instance of this list. 7767992b6aSRichard Cissee * 7867992b6aSRichard Cissee * @return string 7967992b6aSRichard Cissee */ 8067992b6aSRichard Cissee public function listTitle(): string 8167992b6aSRichard Cissee { 8267992b6aSRichard Cissee return $this->title(); 8367992b6aSRichard Cissee } 8467992b6aSRichard Cissee 8567992b6aSRichard Cissee /** 8667992b6aSRichard Cissee * The URL for a page showing list options. 8767992b6aSRichard Cissee * 8867992b6aSRichard Cissee * @param Tree $tree 8976d39c55SGreg Roach * @param array<bool|int|string|array<string>|null> $parameters 9067992b6aSRichard Cissee * 9167992b6aSRichard Cissee * @return string 9267992b6aSRichard Cissee */ 9367992b6aSRichard Cissee public function listUrl(Tree $tree, array $parameters = []): string 9467992b6aSRichard Cissee { 9567992b6aSRichard Cissee return route('module', [ 9667992b6aSRichard Cissee 'module' => $this->name(), 9767992b6aSRichard Cissee 'action' => 'List', 989022ab66SGreg Roach 'tree' => $tree->name(), 9967992b6aSRichard Cissee ] + $parameters); 10067992b6aSRichard Cissee } 10167992b6aSRichard Cissee 10267992b6aSRichard Cissee /** 10367992b6aSRichard Cissee * Attributes for the URL. 10467992b6aSRichard Cissee * 10524f2a3afSGreg Roach * @return array<string> 10667992b6aSRichard Cissee */ 10767992b6aSRichard Cissee public function listUrlAttributes(): array 10867992b6aSRichard Cissee { 10967992b6aSRichard Cissee return ['rel' => 'nofollow']; 11067992b6aSRichard Cissee } 11167992b6aSRichard Cissee 1124db4b4a9SGreg Roach /** 1134db4b4a9SGreg Roach * @param Tree $tree 1144db4b4a9SGreg Roach * 1154db4b4a9SGreg Roach * @return bool 1164db4b4a9SGreg Roach */ 11749528f2bSGreg Roach public function listIsEmpty(Tree $tree): bool 11867992b6aSRichard Cissee { 11967992b6aSRichard Cissee return false; 12067992b6aSRichard Cissee } 12167992b6aSRichard Cissee} 122