. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Menu; use Fisharebest\Webtrees\Tree; /** * Trait ModuleListTrait - default implementation of ModuleListInterface */ trait ModuleListTrait { /** * A main menu item for this list, or null if the list is empty. * * @param Tree $tree * * @return Menu|null */ public function listMenu(Tree $tree): ?Menu { if ($this->listIsEmpty($tree)) { return null; } return new Menu( $this->listTitle(), $this->listUrl($tree), $this->listMenuClass(), $this->listUrlAttributes() ); } /** * CSS class for the menu. * * @return string */ public function listMenuClass(): string { return ''; } /** * The title for a specific instance of this list. * * @return string */ public function listTitle(): string { return $this->title(); } /** * The URL for a page showing list options. * * @param Tree $tree * @param array $parameters * * @return string */ public function listUrl(Tree $tree, array $parameters = []): string { return route('module', [ 'module' => $this->name(), 'action' => 'List', 'tree' => $tree->name(), ] + $parameters); } /** * Attributes for the URL. * * @return array */ public function listUrlAttributes(): array { return ['rel' => 'nofollow']; } /** * @param Tree $tree * * @return bool */ public function listIsEmpty(Tree $tree): bool { return false; } }