xref: /webtrees/app/Module/ModuleMenuTrait.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
149a243cbSGreg Roach<?php
2*3976b470SGreg Roach
349a243cbSGreg Roach/**
449a243cbSGreg Roach * webtrees: online genealogy
549a243cbSGreg Roach * Copyright (C) 2019 webtrees development team
649a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
749a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
849a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
949a243cbSGreg Roach * (at your option) any later version.
1049a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1149a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1249a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1349a243cbSGreg Roach * GNU General Public License for more details.
1449a243cbSGreg Roach * You should have received a copy of the GNU General Public License
1549a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1649a243cbSGreg Roach */
1749a243cbSGreg Roachdeclare(strict_types=1);
1849a243cbSGreg Roach
1949a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
2049a243cbSGreg Roach
2133c34396SGreg Roachuse Fisharebest\Webtrees\Menu;
2233c34396SGreg Roachuse Fisharebest\Webtrees\Tree;
2333c34396SGreg Roach
2449a243cbSGreg Roach/**
2549a243cbSGreg Roach * Trait ModuleMenuTrait - default implementation of ModuleMenuInterface
2649a243cbSGreg Roach */
2749a243cbSGreg Roachtrait ModuleMenuTrait
2849a243cbSGreg Roach{
2949a243cbSGreg Roach    /** @var int The default position for this menu.  It can be changed in the control panel. */
30fb7a0427SGreg Roach    protected $menu_order;
3149a243cbSGreg Roach
3249a243cbSGreg Roach    /**
3349a243cbSGreg Roach     * Users change change the order of menus using the control panel.
3449a243cbSGreg Roach     *
3549a243cbSGreg Roach     * @param int $menu_order
3649a243cbSGreg Roach     *
3749a243cbSGreg Roach     * @return void
3849a243cbSGreg Roach     */
3949a243cbSGreg Roach    public function setMenuOrder(int $menu_order): void
4049a243cbSGreg Roach    {
4149a243cbSGreg Roach        $this->menu_order = $menu_order;
4249a243cbSGreg Roach    }
4349a243cbSGreg Roach
4449a243cbSGreg Roach    /**
4549a243cbSGreg Roach     * Users change change the order of menus using the control panel.
4649a243cbSGreg Roach     *
4749a243cbSGreg Roach     * @return int
4849a243cbSGreg Roach     */
4949a243cbSGreg Roach    public function getMenuOrder(): int
5049a243cbSGreg Roach    {
5124bd2cf5SGreg Roach        return $this->menu_order ?? $this->defaultMenuOrder();
5249a243cbSGreg Roach    }
5349a243cbSGreg Roach
5449a243cbSGreg Roach    /**
5549a243cbSGreg Roach     * The default position for this menu.
5649a243cbSGreg Roach     *
5749a243cbSGreg Roach     * @return int
5849a243cbSGreg Roach     */
59c1afbf58SGreg Roach    public function defaultMenuOrder(): int
6049a243cbSGreg Roach    {
6149a243cbSGreg Roach        return 9999;
6249a243cbSGreg Roach    }
6333c34396SGreg Roach
6433c34396SGreg Roach    /**
6533c34396SGreg Roach     * A menu, to be added to the main application menu.
6633c34396SGreg Roach     *
6733c34396SGreg Roach     * @param Tree $tree
6833c34396SGreg Roach     *
6933c34396SGreg Roach     * @return Menu|null
7033c34396SGreg Roach     */
7133c34396SGreg Roach    public function getMenu(Tree $tree): ?Menu
7233c34396SGreg Roach    {
7333c34396SGreg Roach        return null;
7433c34396SGreg Roach    }
7549a243cbSGreg Roach}
76