xref: /webtrees/app/Module/ModuleThemeTrait.php (revision a091ac74647eab281b25090b737835eeea14ae10)
149a243cbSGreg Roach<?php
23976b470SGreg Roach
349a243cbSGreg Roach/**
449a243cbSGreg Roach * webtrees: online genealogy
5*a091ac74SGreg Roach * Copyright (C) 2020 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 */
17fcfa147eSGreg Roach
1849a243cbSGreg Roachdeclare(strict_types=1);
1949a243cbSGreg Roach
2049a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
2149a243cbSGreg Roach
22de2aa325SGreg Roachuse Aura\Router\Route;
23ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth;
24ade503dfSGreg Roachuse Fisharebest\Webtrees\Fact;
25*a091ac74SGreg Roachuse Fisharebest\Webtrees\Factory;
26ade503dfSGreg Roachuse Fisharebest\Webtrees\Gedcom;
27a49d0e3fSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AccountEdit;
280c0910bfSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
29ea101122SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\HomePage;
3056f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\LoginPage;
3156f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\Logout;
3222e73debSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\PendingChanges;
337adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectLanguage;
347adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectTheme;
358e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\TreePage;
368e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\TreePageEdit;
378e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\UserPage;
388e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\UserPageEdit;
39ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N;
40ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual;
41ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu;
424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
43ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree;
447c4add84SGreg Roachuse Fisharebest\Webtrees\User;
456ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
463976b470SGreg Roach
476ccdf4f0SGreg Roachuse function app;
48de2aa325SGreg Roachuse function assert;
497adfb8e5SGreg Roachuse function route;
50f78837dcSGreg Roachuse function view;
51ade503dfSGreg Roach
5249a243cbSGreg Roach/**
5349a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface
5449a243cbSGreg Roach */
5549a243cbSGreg Roachtrait ModuleThemeTrait
5649a243cbSGreg Roach{
57ade503dfSGreg Roach    /**
58962ead51SGreg Roach     * @return string
59962ead51SGreg Roach     */
60962ead51SGreg Roach    abstract public function name(): string;
61962ead51SGreg Roach
62962ead51SGreg Roach    /**
63962ead51SGreg Roach     * @return string
64962ead51SGreg Roach     */
65962ead51SGreg Roach    abstract public function title(): string;
66962ead51SGreg Roach
67962ead51SGreg Roach    /**
683d8b2a8eSGreg Roach     * A sentence describing what this module does.
693d8b2a8eSGreg Roach     *
703d8b2a8eSGreg Roach     * @return string
713d8b2a8eSGreg Roach     */
723d8b2a8eSGreg Roach    public function description(): string
733d8b2a8eSGreg Roach    {
743d8b2a8eSGreg Roach        return I18N::translate('Theme') . ' — ' . $this->title();
753d8b2a8eSGreg Roach    }
763d8b2a8eSGreg Roach
773d8b2a8eSGreg Roach    /**
78ade503dfSGreg Roach     * Generate the facts, for display in charts.
79ade503dfSGreg Roach     *
80ade503dfSGreg Roach     * @param Individual $individual
81ade503dfSGreg Roach     *
82ade503dfSGreg Roach     * @return string
83ade503dfSGreg Roach     */
84ade503dfSGreg Roach    public function individualBoxFacts(Individual $individual): string
85ade503dfSGreg Roach    {
86ade503dfSGreg Roach        $html = '';
87ade503dfSGreg Roach
88ade503dfSGreg Roach        $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
89ade503dfSGreg Roach        // Show BIRT or equivalent event
90ade503dfSGreg Roach        foreach (Gedcom::BIRTH_EVENTS as $birttag) {
9122d65e5aSGreg Roach            if (!in_array($birttag, $opt_tags, true)) {
92820b62dfSGreg Roach                $event = $individual->facts([$birttag])->first();
93820b62dfSGreg Roach                if ($event instanceof Fact) {
94ade503dfSGreg Roach                    $html .= $event->summary();
95ade503dfSGreg Roach                    break;
96ade503dfSGreg Roach                }
97ade503dfSGreg Roach            }
98ade503dfSGreg Roach        }
99ade503dfSGreg Roach        // Show optional events (before death)
100ade503dfSGreg Roach        foreach ($opt_tags as $key => $tag) {
10122d65e5aSGreg Roach            if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
102820b62dfSGreg Roach                $event = $individual->facts([$tag])->first();
103820b62dfSGreg Roach                if ($event instanceof Fact) {
104ade503dfSGreg Roach                    $html .= $event->summary();
105ade503dfSGreg Roach                    unset($opt_tags[$key]);
106ade503dfSGreg Roach                }
107ade503dfSGreg Roach            }
108ade503dfSGreg Roach        }
109ade503dfSGreg Roach        // Show DEAT or equivalent event
110ade503dfSGreg Roach        foreach (Gedcom::DEATH_EVENTS as $deattag) {
111820b62dfSGreg Roach            $event = $individual->facts([$deattag])->first();
112820b62dfSGreg Roach            if ($event instanceof Fact) {
113ade503dfSGreg Roach                $html .= $event->summary();
11422d65e5aSGreg Roach                if (in_array($deattag, $opt_tags, true)) {
11522d65e5aSGreg Roach                    unset($opt_tags[array_search($deattag, $opt_tags, true)]);
116ade503dfSGreg Roach                }
117ade503dfSGreg Roach                break;
118ade503dfSGreg Roach            }
119ade503dfSGreg Roach        }
120ade503dfSGreg Roach        // Show remaining optional events (after death)
121ade503dfSGreg Roach        foreach ($opt_tags as $tag) {
122820b62dfSGreg Roach            $event = $individual->facts([$tag])->first();
123820b62dfSGreg Roach            if ($event instanceof Fact) {
124ade503dfSGreg Roach                $html .= $event->summary();
125ade503dfSGreg Roach            }
126ade503dfSGreg Roach        }
127ade503dfSGreg Roach
128ade503dfSGreg Roach        return $html;
129ade503dfSGreg Roach    }
130ade503dfSGreg Roach
131ade503dfSGreg Roach    /**
132ade503dfSGreg Roach     * Links, to show in chart boxes;
133ade503dfSGreg Roach     *
134ade503dfSGreg Roach     * @param Individual $individual
135ade503dfSGreg Roach     *
136ade503dfSGreg Roach     * @return Menu[]
137ade503dfSGreg Roach     */
138ade503dfSGreg Roach    public function individualBoxMenu(Individual $individual): array
139ade503dfSGreg Roach    {
140aa6311c7SGreg Roach        return array_merge(
141ade503dfSGreg Roach            $this->individualBoxMenuCharts($individual),
142ade503dfSGreg Roach            $this->individualBoxMenuFamilyLinks($individual)
143ade503dfSGreg Roach        );
144ade503dfSGreg Roach    }
145ade503dfSGreg Roach
146ade503dfSGreg Roach    /**
147ade503dfSGreg Roach     * Chart links, to show in chart boxes;
148ade503dfSGreg Roach     *
149ade503dfSGreg Roach     * @param Individual $individual
150ade503dfSGreg Roach     *
151ade503dfSGreg Roach     * @return Menu[]
152ade503dfSGreg Roach     */
153ade503dfSGreg Roach    public function individualBoxMenuCharts(Individual $individual): array
154ade503dfSGreg Roach    {
155ade503dfSGreg Roach        $menus = [];
156f39638cfSGreg Roach        foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) {
157ade503dfSGreg Roach            $menu = $chart->chartBoxMenu($individual);
158ade503dfSGreg Roach            if ($menu) {
159ade503dfSGreg Roach                $menus[] = $menu;
160ade503dfSGreg Roach            }
161ade503dfSGreg Roach        }
162ade503dfSGreg Roach
1630b93976aSGreg Roach        usort($menus, static function (Menu $x, Menu $y): int {
164ade503dfSGreg Roach            return I18N::strcasecmp($x->getLabel(), $y->getLabel());
165ade503dfSGreg Roach        });
166ade503dfSGreg Roach
167ade503dfSGreg Roach        return $menus;
168ade503dfSGreg Roach    }
169ade503dfSGreg Roach
170ade503dfSGreg Roach    /**
171ade503dfSGreg Roach     * Family links, to show in chart boxes.
172ade503dfSGreg Roach     *
173ade503dfSGreg Roach     * @param Individual $individual
174ade503dfSGreg Roach     *
175ade503dfSGreg Roach     * @return Menu[]
176ade503dfSGreg Roach     */
177ade503dfSGreg Roach    public function individualBoxMenuFamilyLinks(Individual $individual): array
178ade503dfSGreg Roach    {
179ade503dfSGreg Roach        $menus = [];
180ade503dfSGreg Roach
18139ca88baSGreg Roach        foreach ($individual->spouseFamilies() as $family) {
182ade503dfSGreg Roach            $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url());
18339ca88baSGreg Roach            $spouse  = $family->spouse($individual);
184ade503dfSGreg Roach            if ($spouse && $spouse->canShowName()) {
18539ca88baSGreg Roach                $menus[] = new Menu($spouse->fullName(), $spouse->url());
186ade503dfSGreg Roach            }
18739ca88baSGreg Roach            foreach ($family->children() as $child) {
188ade503dfSGreg Roach                if ($child->canShowName()) {
18939ca88baSGreg Roach                    $menus[] = new Menu($child->fullName(), $child->url());
190ade503dfSGreg Roach                }
191ade503dfSGreg Roach            }
192ade503dfSGreg Roach        }
193ade503dfSGreg Roach
194ade503dfSGreg Roach        return $menus;
195ade503dfSGreg Roach    }
196ade503dfSGreg Roach
197ade503dfSGreg Roach    /**
198f567c3d8SGreg Roach     * Generate a menu item to change the blocks on the current tree/user page.
199ade503dfSGreg Roach     *
2000c8c69d4SGreg Roach     * @param Tree $tree
2010c8c69d4SGreg Roach     *
202ade503dfSGreg Roach     * @return Menu|null
203ade503dfSGreg Roach     */
204e364afe4SGreg Roach    public function menuChangeBlocks(Tree $tree): ?Menu
205ade503dfSGreg Roach    {
206eb235819SGreg Roach        /** @var ServerRequestInterface $request */
2076ccdf4f0SGreg Roach        $request = app(ServerRequestInterface::class);
208e6bcfa02SGreg Roach
2090d7461faSGreg Roach        $route = $request->getAttribute('route');
210de2aa325SGreg Roach        assert($route instanceof Route);
211eb235819SGreg Roach
212de2aa325SGreg Roach        if (Auth::check() && $route->name === UserPage::class) {
2138e0e1b25SGreg Roach            return new Menu(I18N::translate('Customize this page'), route(UserPageEdit::class, ['tree' => $tree->name()]), 'menu-change-blocks');
214ade503dfSGreg Roach        }
215ade503dfSGreg Roach
216de2aa325SGreg Roach        if (Auth::isManager($tree) && $route->name === TreePage::class) {
2178e0e1b25SGreg Roach            return new Menu(I18N::translate('Customize this page'), route(TreePageEdit::class, ['tree' => $tree->name()]), 'menu-change-blocks');
218ade503dfSGreg Roach        }
219ade503dfSGreg Roach
220ade503dfSGreg Roach        return null;
221ade503dfSGreg Roach    }
222ade503dfSGreg Roach
223ade503dfSGreg Roach    /**
224ade503dfSGreg Roach     * Generate a menu item for the control panel.
225ade503dfSGreg Roach     *
2260c8c69d4SGreg Roach     * @param Tree $tree
2270c8c69d4SGreg Roach     *
228ade503dfSGreg Roach     * @return Menu|null
229ade503dfSGreg Roach     */
230e364afe4SGreg Roach    public function menuControlPanel(Tree $tree): ?Menu
231ade503dfSGreg Roach    {
232ade503dfSGreg Roach        if (Auth::isAdmin()) {
2330c0910bfSGreg Roach            return new Menu(I18N::translate('Control panel'), route(ControlPanel::class), 'menu-admin');
234ade503dfSGreg Roach        }
235ade503dfSGreg Roach
2360c8c69d4SGreg Roach        if (Auth::isManager($tree)) {
2376f414251SGreg Roach            return new Menu(I18N::translate('Control panel'), route('manage-trees', ['tree' => $tree->name()]), 'menu-admin');
238ade503dfSGreg Roach        }
239ade503dfSGreg Roach
240ade503dfSGreg Roach        return null;
241ade503dfSGreg Roach    }
242ade503dfSGreg Roach
243ade503dfSGreg Roach    /**
244ade503dfSGreg Roach     * A menu to show a list of available languages.
245ade503dfSGreg Roach     *
246ade503dfSGreg Roach     * @return Menu|null
247ade503dfSGreg Roach     */
248e364afe4SGreg Roach    public function menuLanguages(): ?Menu
249ade503dfSGreg Roach    {
250ade503dfSGreg Roach        $menu = new Menu(I18N::translate('Language'), '#', 'menu-language');
251ade503dfSGreg Roach
25290a2f718SGreg Roach        foreach (I18N::activeLocales() as $active_locale) {
25390a2f718SGreg Roach            $language_tag = $active_locale->languageTag();
25465cf5706SGreg Roach            $class        = 'menu-language-' . $language_tag . (I18N::languageTag() === $language_tag ? ' active' : '');
25590a2f718SGreg Roach            $menu->addSubmenu(new Menu($active_locale->endonym(), '#', $class, [
2567adfb8e5SGreg Roach                'data-post-url' => route(SelectLanguage::class, ['language' => $language_tag]),
257ade503dfSGreg Roach            ]));
258ade503dfSGreg Roach        }
259ade503dfSGreg Roach
260ade503dfSGreg Roach        if (count($menu->getSubmenus()) > 1) {
261ade503dfSGreg Roach            return $menu;
262ade503dfSGreg Roach        }
263ade503dfSGreg Roach
264ade503dfSGreg Roach        return null;
265ade503dfSGreg Roach    }
266ade503dfSGreg Roach
267ade503dfSGreg Roach    /**
268ade503dfSGreg Roach     * A login menu option (or null if we are already logged in).
269ade503dfSGreg Roach     *
270ade503dfSGreg Roach     * @return Menu|null
271ade503dfSGreg Roach     */
272e364afe4SGreg Roach    public function menuLogin(): ?Menu
273ade503dfSGreg Roach    {
274ade503dfSGreg Roach        if (Auth::check()) {
275ade503dfSGreg Roach            return null;
276ade503dfSGreg Roach        }
277ade503dfSGreg Roach
27886661454SGreg Roach        $request = app(ServerRequestInterface::class);
27986661454SGreg Roach
280ade503dfSGreg Roach        // Return to this page after login...
281b6c0b825SGreg Roach        $redirect = $request->getQueryParams()['url'] ?? (string) $request->getUri();
282ade503dfSGreg Roach
283b45ccc4fSGreg Roach        $tree  = $request->getAttribute('tree');
284de2aa325SGreg Roach        $route = $request->getAttribute('route');
285de2aa325SGreg Roach        assert($route instanceof Route);
286b45ccc4fSGreg Roach
287ade503dfSGreg Roach        // ...but switch from the tree-page to the user-page
288de2aa325SGreg Roach        if ($route->name === TreePage::class) {
2898e0e1b25SGreg Roach            $redirect = route(UserPage::class, ['tree' => $tree instanceof Tree ? $tree->name() : null]);
29091c514e5SGreg Roach        }
291ade503dfSGreg Roach
29286661454SGreg Roach        // Stay on the same tree page
29391c514e5SGreg Roach        $url  = route(LoginPage::class, ['tree' => $tree instanceof Tree ? $tree->name() : null, 'url' => $redirect]);
29486661454SGreg Roach
29586661454SGreg Roach        return new Menu(I18N::translate('Sign in'), $url, 'menu-login', ['rel' => 'nofollow']);
296ade503dfSGreg Roach    }
297ade503dfSGreg Roach
298ade503dfSGreg Roach    /**
299ade503dfSGreg Roach     * A logout menu option (or null if we are already logged out).
300ade503dfSGreg Roach     *
301ade503dfSGreg Roach     * @return Menu|null
302ade503dfSGreg Roach     */
303e364afe4SGreg Roach    public function menuLogout(): ?Menu
304ade503dfSGreg Roach    {
305ade503dfSGreg Roach        if (Auth::check()) {
3069b541e4aSGreg Roach            $parameters = [
3079b541e4aSGreg Roach                'data-post-url'   => route(Logout::class),
308ea101122SGreg Roach                'data-reload-url' => route(HomePage::class)
3099b541e4aSGreg Roach            ];
3109b541e4aSGreg Roach
3119b541e4aSGreg Roach            return new Menu(I18N::translate('Sign out'), '#', 'menu-logout', $parameters);
312ade503dfSGreg Roach        }
313ade503dfSGreg Roach
314ade503dfSGreg Roach        return null;
315ade503dfSGreg Roach    }
316ade503dfSGreg Roach
317ade503dfSGreg Roach    /**
318ade503dfSGreg Roach     * A link to allow users to edit their account settings.
319ade503dfSGreg Roach     *
32065aec466SGreg Roach     * @param Tree|null $tree
321a49d0e3fSGreg Roach     *
322a49d0e3fSGreg Roach     * @return Menu
323ade503dfSGreg Roach     */
324a49d0e3fSGreg Roach    public function menuMyAccount(?Tree $tree): Menu
325ade503dfSGreg Roach    {
326a49d0e3fSGreg Roach        $url = route(AccountEdit::class, ['tree' => $tree instanceof Tree ? $tree->name() : null]);
327ade503dfSGreg Roach
328df314983SGreg Roach        return new Menu(I18N::translate('My account'), $url, 'menu-myaccount');
329ade503dfSGreg Roach    }
330ade503dfSGreg Roach
331ade503dfSGreg Roach    /**
332ade503dfSGreg Roach     * A link to the user's individual record (individual.php).
333ade503dfSGreg Roach     *
3340c8c69d4SGreg Roach     * @param Tree $tree
3350c8c69d4SGreg Roach     *
336ade503dfSGreg Roach     * @return Menu|null
337ade503dfSGreg Roach     */
338e364afe4SGreg Roach    public function menuMyIndividualRecord(Tree $tree): ?Menu
339ade503dfSGreg Roach    {
340*a091ac74SGreg Roach        $record = Factory::individual()->make($tree->getUserPreference(Auth::user(), User::PREF_TREE_ACCOUNT_XREF), $tree);
341ade503dfSGreg Roach
342ade503dfSGreg Roach        if ($record) {
343ade503dfSGreg Roach            return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord');
344ade503dfSGreg Roach        }
345ade503dfSGreg Roach
346ade503dfSGreg Roach        return null;
347ade503dfSGreg Roach    }
348ade503dfSGreg Roach
349ade503dfSGreg Roach    /**
350ade503dfSGreg Roach     * A link to the user's personal home page.
351ade503dfSGreg Roach     *
3520c8c69d4SGreg Roach     * @param Tree $tree
3530c8c69d4SGreg Roach     *
354ade503dfSGreg Roach     * @return Menu
355ade503dfSGreg Roach     */
3560c8c69d4SGreg Roach    public function menuMyPage(Tree $tree): Menu
357ade503dfSGreg Roach    {
3588e0e1b25SGreg Roach        return new Menu(I18N::translate('My page'), route(UserPage::class, ['tree' => $tree->name()]), 'menu-mypage');
359ade503dfSGreg Roach    }
360ade503dfSGreg Roach
361ade503dfSGreg Roach    /**
362ade503dfSGreg Roach     * A menu for the user's personal pages.
363ade503dfSGreg Roach     *
3640c8c69d4SGreg Roach     * @param Tree|null $tree
3650c8c69d4SGreg Roach     *
366ade503dfSGreg Roach     * @return Menu|null
367ade503dfSGreg Roach     */
368e364afe4SGreg Roach    public function menuMyPages(?Tree $tree): ?Menu
369ade503dfSGreg Roach    {
370a49d0e3fSGreg Roach        if (Auth::id()) {
371a49d0e3fSGreg Roach            if ($tree instanceof Tree) {
372ade503dfSGreg Roach                return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([
3730c8c69d4SGreg Roach                    $this->menuMyPage($tree),
3740c8c69d4SGreg Roach                    $this->menuMyIndividualRecord($tree),
3750c8c69d4SGreg Roach                    $this->menuMyPedigree($tree),
376a49d0e3fSGreg Roach                    $this->menuMyAccount($tree),
3770c8c69d4SGreg Roach                    $this->menuControlPanel($tree),
3780c8c69d4SGreg Roach                    $this->menuChangeBlocks($tree),
379ade503dfSGreg Roach                ]));
380ade503dfSGreg Roach            }
381ade503dfSGreg Roach
382a49d0e3fSGreg Roach            return $this->menuMyAccount($tree);
383a49d0e3fSGreg Roach        }
384a49d0e3fSGreg Roach
385ade503dfSGreg Roach        return null;
386ade503dfSGreg Roach    }
387ade503dfSGreg Roach
388ade503dfSGreg Roach    /**
389ade503dfSGreg Roach     * A link to the user's individual record.
390ade503dfSGreg Roach     *
3910c8c69d4SGreg Roach     * @param Tree $tree
3920c8c69d4SGreg Roach     *
393ade503dfSGreg Roach     * @return Menu|null
394ade503dfSGreg Roach     */
395e364afe4SGreg Roach    public function menuMyPedigree(Tree $tree): ?Menu
396ade503dfSGreg Roach    {
3977c4add84SGreg Roach        $gedcomid = $tree->getUserPreference(Auth::user(), User::PREF_TREE_ACCOUNT_XREF);
398ade503dfSGreg Roach
3990c8c69d4SGreg Roach        $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
4000b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module): bool {
401ade503dfSGreg Roach                return $module instanceof PedigreeChartModule;
402ade503dfSGreg Roach            });
403ade503dfSGreg Roach
404ade503dfSGreg Roach        if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) {
405ade503dfSGreg Roach            return new Menu(
406ade503dfSGreg Roach                I18N::translate('My pedigree'),
407ade503dfSGreg Roach                route('pedigree', [
408ade503dfSGreg Roach                    'xref' => $gedcomid,
4099022ab66SGreg Roach                    'tree'  => $tree->name(),
410ade503dfSGreg Roach                ]),
411ade503dfSGreg Roach                'menu-mypedigree'
412ade503dfSGreg Roach            );
413ade503dfSGreg Roach        }
414ade503dfSGreg Roach
415ade503dfSGreg Roach        return null;
416ade503dfSGreg Roach    }
417ade503dfSGreg Roach
418ade503dfSGreg Roach    /**
419ade503dfSGreg Roach     * Create a pending changes menu.
420ade503dfSGreg Roach     *
4210c8c69d4SGreg Roach     * @param Tree|null $tree
4220c8c69d4SGreg Roach     *
423ade503dfSGreg Roach     * @return Menu|null
424ade503dfSGreg Roach     */
425e364afe4SGreg Roach    public function menuPendingChanges(?Tree $tree): ?Menu
426ade503dfSGreg Roach    {
4270c8c69d4SGreg Roach        if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) {
42822e73debSGreg Roach            $url = route(PendingChanges::class, [
4299022ab66SGreg Roach                'tree' => $tree->name(),
430cf8c0692SGreg Roach                'url' => (string) app(ServerRequestInterface::class)->getUri(),
431ade503dfSGreg Roach            ]);
432ade503dfSGreg Roach
433ade503dfSGreg Roach            return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending');
434ade503dfSGreg Roach        }
435ade503dfSGreg Roach
436ade503dfSGreg Roach        return null;
437ade503dfSGreg Roach    }
438ade503dfSGreg Roach
439ade503dfSGreg Roach    /**
440ade503dfSGreg Roach     * Themes menu.
441ade503dfSGreg Roach     *
442ade503dfSGreg Roach     * @return Menu|null
443ade503dfSGreg Roach     */
444e364afe4SGreg Roach    public function menuThemes(): ?Menu
445ade503dfSGreg Roach    {
446b668782fSGreg Roach        $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true);
447df8baf00SGreg Roach
448cab242e7SGreg Roach        $current_theme = app(ModuleThemeInterface::class);
4498136679eSGreg Roach
4508136679eSGreg Roach        if ($themes->count() > 1) {
4510b5fd0a6SGreg Roach            $submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu {
4528136679eSGreg Roach                $active     = $theme->name() === $current_theme->name();
4538136679eSGreg Roach                $class      = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');
4548136679eSGreg Roach
4558136679eSGreg Roach                return new Menu($theme->title(), '#', $class, [
4567adfb8e5SGreg Roach                    'data-post-url' => route(SelectTheme::class, ['theme' => $theme->name()]),
457ade503dfSGreg Roach                ]);
458ade503dfSGreg Roach            });
459ade503dfSGreg Roach
4608136679eSGreg Roach            return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all());
461ade503dfSGreg Roach        }
462ade503dfSGreg Roach
463ade503dfSGreg Roach        return null;
464ade503dfSGreg Roach    }
465ade503dfSGreg Roach
466ade503dfSGreg Roach    /**
467ade503dfSGreg Roach     * Misecellaneous dimensions, fonts, styles, etc.
468ade503dfSGreg Roach     *
469ade503dfSGreg Roach     * @param string $parameter_name
470ade503dfSGreg Roach     *
471ade503dfSGreg Roach     * @return string|int|float
472ade503dfSGreg Roach     */
473ade503dfSGreg Roach    public function parameter($parameter_name)
474ade503dfSGreg Roach    {
475ade503dfSGreg Roach        return '';
476ade503dfSGreg Roach    }
477ade503dfSGreg Roach
478ade503dfSGreg Roach    /**
479ade503dfSGreg Roach     * Generate a list of items for the main menu.
480ade503dfSGreg Roach     *
4810c8c69d4SGreg Roach     * @param Tree|null $tree
4820c8c69d4SGreg Roach     *
483ade503dfSGreg Roach     * @return Menu[]
484ade503dfSGreg Roach     */
4850c8c69d4SGreg Roach    public function genealogyMenu(?Tree $tree): array
486ade503dfSGreg Roach    {
4870c8c69d4SGreg Roach        if ($tree === null) {
4880c8c69d4SGreg Roach            return [];
4890c8c69d4SGreg Roach        }
4900c8c69d4SGreg Roach
4910c8c69d4SGreg Roach        return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user())
4920b5fd0a6SGreg Roach            ->map(static function (ModuleMenuInterface $menu) use ($tree): ?Menu {
4930c8c69d4SGreg Roach                return $menu->getMenu($tree);
494ade503dfSGreg Roach            })
495ade503dfSGreg Roach            ->filter()
496ade503dfSGreg Roach            ->all();
497ade503dfSGreg Roach    }
498ade503dfSGreg Roach
499ade503dfSGreg Roach    /**
5000c8c69d4SGreg Roach     * Create the genealogy menu.
501ade503dfSGreg Roach     *
502ade503dfSGreg Roach     * @param Menu[] $menus
503ade503dfSGreg Roach     *
504ade503dfSGreg Roach     * @return string
505ade503dfSGreg Roach     */
5060c8c69d4SGreg Roach    public function genealogyMenuContent(array $menus): string
507ade503dfSGreg Roach    {
5080b5fd0a6SGreg Roach        return implode('', array_map(static function (Menu $menu): string {
509f78837dcSGreg Roach            return view('components/menu-item', ['menu' => $menu]);
510ade503dfSGreg Roach        }, $menus));
511ade503dfSGreg Roach    }
512ade503dfSGreg Roach
513ade503dfSGreg Roach    /**
514ade503dfSGreg Roach     * Generate a list of items for the user menu.
515ade503dfSGreg Roach     *
5160c8c69d4SGreg Roach     * @param Tree|null $tree
5170c8c69d4SGreg Roach     *
518ade503dfSGreg Roach     * @return Menu[]
519ade503dfSGreg Roach     */
5200c8c69d4SGreg Roach    public function userMenu(?Tree $tree): array
521ade503dfSGreg Roach    {
522ade503dfSGreg Roach        return array_filter([
5230c8c69d4SGreg Roach            $this->menuPendingChanges($tree),
5240c8c69d4SGreg Roach            $this->menuMyPages($tree),
525ade503dfSGreg Roach            $this->menuThemes(),
526ade503dfSGreg Roach            $this->menuLanguages(),
527ade503dfSGreg Roach            $this->menuLogin(),
528ade503dfSGreg Roach            $this->menuLogout(),
529ade503dfSGreg Roach        ]);
530ade503dfSGreg Roach    }
531ade503dfSGreg Roach
532ade503dfSGreg Roach    /**
533ade503dfSGreg Roach     * A list of CSS files to include for this page.
534ade503dfSGreg Roach     *
535ade503dfSGreg Roach     * @return string[]
536ade503dfSGreg Roach     */
537ade503dfSGreg Roach    public function stylesheets(): array
538ade503dfSGreg Roach    {
539ade503dfSGreg Roach        return [];
540ade503dfSGreg Roach    }
54149a243cbSGreg Roach}
542