xref: /webtrees/app/Module/ModuleSidebarTrait.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\Individual;
23use Illuminate\Support\Collection;
24
25/**
26 * Trait ModuleSidebarTrait - default implementation of ModuleSidebarInterface
27 */
28trait ModuleSidebarTrait
29{
30    // The default position for this sidebar.  It can be changed in the control panel.
31    protected int $sidebar_order;
32
33    /**
34     * How should this module be identified in the control panel, etc.?
35     *
36     * @return string
37     */
38    abstract public function title(): string;
39
40    /**
41     * The text that appears on the sidebar's title.
42     *
43     * @param Individual $individual
44     *
45     * @return string
46     */
47    public function sidebarTitle(Individual $individual): string
48    {
49        return $this->title();
50    }
51
52    /**
53     * Users change change the order of sidebars using the control panel.
54     *
55     * @param int $sidebar_order
56     *
57     * @return void
58     */
59    public function setSidebarOrder(int $sidebar_order): void
60    {
61        $this->sidebar_order = $sidebar_order;
62    }
63
64    /**
65     * Users change change the order of sidebars using the control panel.
66     *
67     * @return int
68     */
69    public function getSidebarOrder(): int
70    {
71        return $this->sidebar_order ?? $this->defaultSidebarOrder();
72    }
73
74    /**
75     * The default position for this sidebar.
76     *
77     * @return int
78     */
79    public function defaultSidebarOrder(): int
80    {
81        return 9999;
82    }
83
84    /**
85     * This module handles the following facts - so don't show them on the "Facts and events" tab.
86     *
87     * @return Collection<int,string>
88     */
89    public function supportedFacts(): Collection
90    {
91        return new Collection();
92    }
93}
94