xref: /webtrees/app/Module/ModuleThemeTrait.php (revision 22d65e5ad7724941da33d875027b68b86648a321)
149a243cbSGreg Roach<?php
249a243cbSGreg Roach/**
349a243cbSGreg Roach * webtrees: online genealogy
449a243cbSGreg Roach * Copyright (C) 2019 webtrees development team
549a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
649a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
749a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
849a243cbSGreg Roach * (at your option) any later version.
949a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1049a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1149a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1249a243cbSGreg Roach * GNU General Public License for more details.
1349a243cbSGreg Roach * You should have received a copy of the GNU General Public License
1449a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1549a243cbSGreg Roach */
1649a243cbSGreg Roachdeclare(strict_types=1);
1749a243cbSGreg Roach
1849a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
1949a243cbSGreg Roach
20ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth;
21ade503dfSGreg Roachuse Fisharebest\Webtrees\Fact;
22ade503dfSGreg Roachuse Fisharebest\Webtrees\Gedcom;
23ade503dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag;
24ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N;
25ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual;
26ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu;
274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
28ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree;
29f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees;
306ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
316ccdf4f0SGreg Roachuse function app;
32ade503dfSGreg Roach
3349a243cbSGreg Roach/**
3449a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface
3549a243cbSGreg Roach */
3649a243cbSGreg Roachtrait ModuleThemeTrait
3749a243cbSGreg Roach{
38ade503dfSGreg Roach    /**
39ade503dfSGreg Roach     * Display an icon for this fact.
40ade503dfSGreg Roach     *
41e837ff07SGreg Roach     * @TODO use CSS for this
42e837ff07SGreg Roach     *
43ade503dfSGreg Roach     * @param Fact $fact
44ade503dfSGreg Roach     *
45ade503dfSGreg Roach     * @return string
46ade503dfSGreg Roach     */
47ade503dfSGreg Roach    public function icon(Fact $fact): string
48ade503dfSGreg Roach    {
49e837ff07SGreg Roach        $asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png';
50f397d0fdSGreg Roach        if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
51e837ff07SGreg Roach            return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">';
52ade503dfSGreg Roach        }
53ade503dfSGreg Roach
54ade503dfSGreg Roach        // Spacer image - for alignment - until we move to a sprite.
55e837ff07SGreg Roach        $asset = 'public/css/' . $this->name() . '/images/facts/NULL.png';
56f397d0fdSGreg Roach        if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) {
57e837ff07SGreg Roach            return '<img src="' . e(asset($asset)) . '">';
58ade503dfSGreg Roach        }
59ade503dfSGreg Roach
60ade503dfSGreg Roach        return '';
61ade503dfSGreg Roach    }
62ade503dfSGreg Roach
63ade503dfSGreg Roach    /**
64ade503dfSGreg Roach     * Generate the facts, for display in charts.
65ade503dfSGreg Roach     *
66ade503dfSGreg Roach     * @param Individual $individual
67ade503dfSGreg Roach     *
68ade503dfSGreg Roach     * @return string
69ade503dfSGreg Roach     */
70ade503dfSGreg Roach    public function individualBoxFacts(Individual $individual): string
71ade503dfSGreg Roach    {
72ade503dfSGreg Roach        $html = '';
73ade503dfSGreg Roach
74ade503dfSGreg Roach        $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
75ade503dfSGreg Roach        // Show BIRT or equivalent event
76ade503dfSGreg Roach        foreach (Gedcom::BIRTH_EVENTS as $birttag) {
77*22d65e5aSGreg Roach            if (!in_array($birttag, $opt_tags, true)) {
78820b62dfSGreg Roach                $event = $individual->facts([$birttag])->first();
79820b62dfSGreg Roach                if ($event instanceof Fact) {
80ade503dfSGreg Roach                    $html .= $event->summary();
81ade503dfSGreg Roach                    break;
82ade503dfSGreg Roach                }
83ade503dfSGreg Roach            }
84ade503dfSGreg Roach        }
85ade503dfSGreg Roach        // Show optional events (before death)
86ade503dfSGreg Roach        foreach ($opt_tags as $key => $tag) {
87*22d65e5aSGreg Roach            if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
88820b62dfSGreg Roach                $event = $individual->facts([$tag])->first();
89820b62dfSGreg Roach                if ($event instanceof Fact) {
90ade503dfSGreg Roach                    $html .= $event->summary();
91ade503dfSGreg Roach                    unset($opt_tags[$key]);
92ade503dfSGreg Roach                }
93ade503dfSGreg Roach            }
94ade503dfSGreg Roach        }
95ade503dfSGreg Roach        // Show DEAT or equivalent event
96ade503dfSGreg Roach        foreach (Gedcom::DEATH_EVENTS as $deattag) {
97820b62dfSGreg Roach            $event = $individual->facts([$deattag])->first();
98820b62dfSGreg Roach            if ($event instanceof Fact) {
99ade503dfSGreg Roach                $html .= $event->summary();
100*22d65e5aSGreg Roach                if (in_array($deattag, $opt_tags, true)) {
101*22d65e5aSGreg Roach                    unset($opt_tags[array_search($deattag, $opt_tags, true)]);
102ade503dfSGreg Roach                }
103ade503dfSGreg Roach                break;
104ade503dfSGreg Roach            }
105ade503dfSGreg Roach        }
106ade503dfSGreg Roach        // Show remaining optional events (after death)
107ade503dfSGreg Roach        foreach ($opt_tags as $tag) {
108820b62dfSGreg Roach            $event = $individual->facts([$tag])->first();
109820b62dfSGreg Roach            if ($event instanceof Fact) {
110ade503dfSGreg Roach                $html .= $event->summary();
111ade503dfSGreg Roach            }
112ade503dfSGreg Roach        }
113ade503dfSGreg Roach
114ade503dfSGreg Roach        return $html;
115ade503dfSGreg Roach    }
116ade503dfSGreg Roach
117ade503dfSGreg Roach    /**
118ade503dfSGreg Roach     * Links, to show in chart boxes;
119ade503dfSGreg Roach     *
120ade503dfSGreg Roach     * @param Individual $individual
121ade503dfSGreg Roach     *
122ade503dfSGreg Roach     * @return Menu[]
123ade503dfSGreg Roach     */
124ade503dfSGreg Roach    public function individualBoxMenu(Individual $individual): array
125ade503dfSGreg Roach    {
126ade503dfSGreg Roach        $menus = array_merge(
127ade503dfSGreg Roach            $this->individualBoxMenuCharts($individual),
128ade503dfSGreg Roach            $this->individualBoxMenuFamilyLinks($individual)
129ade503dfSGreg Roach        );
130ade503dfSGreg Roach
131ade503dfSGreg Roach        return $menus;
132ade503dfSGreg Roach    }
133ade503dfSGreg Roach
134ade503dfSGreg Roach    /**
135ade503dfSGreg Roach     * Chart links, to show in chart boxes;
136ade503dfSGreg Roach     *
137ade503dfSGreg Roach     * @param Individual $individual
138ade503dfSGreg Roach     *
139ade503dfSGreg Roach     * @return Menu[]
140ade503dfSGreg Roach     */
141ade503dfSGreg Roach    public function individualBoxMenuCharts(Individual $individual): array
142ade503dfSGreg Roach    {
143ade503dfSGreg Roach        $menus = [];
144f39638cfSGreg Roach        foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) {
145ade503dfSGreg Roach            $menu = $chart->chartBoxMenu($individual);
146ade503dfSGreg Roach            if ($menu) {
147ade503dfSGreg Roach                $menus[] = $menu;
148ade503dfSGreg Roach            }
149ade503dfSGreg Roach        }
150ade503dfSGreg Roach
1510b5fd0a6SGreg Roach        usort($menus, static function (Menu $x, Menu $y) {
152ade503dfSGreg Roach            return I18N::strcasecmp($x->getLabel(), $y->getLabel());
153ade503dfSGreg Roach        });
154ade503dfSGreg Roach
155ade503dfSGreg Roach        return $menus;
156ade503dfSGreg Roach    }
157ade503dfSGreg Roach
158ade503dfSGreg Roach    /**
159ade503dfSGreg Roach     * Family links, to show in chart boxes.
160ade503dfSGreg Roach     *
161ade503dfSGreg Roach     * @param Individual $individual
162ade503dfSGreg Roach     *
163ade503dfSGreg Roach     * @return Menu[]
164ade503dfSGreg Roach     */
165ade503dfSGreg Roach    public function individualBoxMenuFamilyLinks(Individual $individual): array
166ade503dfSGreg Roach    {
167ade503dfSGreg Roach        $menus = [];
168ade503dfSGreg Roach
16939ca88baSGreg Roach        foreach ($individual->spouseFamilies() as $family) {
170ade503dfSGreg Roach            $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url());
17139ca88baSGreg Roach            $spouse  = $family->spouse($individual);
172ade503dfSGreg Roach            if ($spouse && $spouse->canShowName()) {
17339ca88baSGreg Roach                $menus[] = new Menu($spouse->fullName(), $spouse->url());
174ade503dfSGreg Roach            }
17539ca88baSGreg Roach            foreach ($family->children() as $child) {
176ade503dfSGreg Roach                if ($child->canShowName()) {
17739ca88baSGreg Roach                    $menus[] = new Menu($child->fullName(), $child->url());
178ade503dfSGreg Roach                }
179ade503dfSGreg Roach            }
180ade503dfSGreg Roach        }
181ade503dfSGreg Roach
182ade503dfSGreg Roach        return $menus;
183ade503dfSGreg Roach    }
184ade503dfSGreg Roach
185ade503dfSGreg Roach    /**
186ade503dfSGreg Roach     * Generate a menu item to change the blocks on the current (index.php) page.
187ade503dfSGreg Roach     *
1880c8c69d4SGreg Roach     * @param Tree $tree
1890c8c69d4SGreg Roach     *
190ade503dfSGreg Roach     * @return Menu|null
191ade503dfSGreg Roach     */
192e364afe4SGreg Roach    public function menuChangeBlocks(Tree $tree): ?Menu
193ade503dfSGreg Roach    {
1946ccdf4f0SGreg Roach        $request = app(ServerRequestInterface::class);
195e6bcfa02SGreg Roach
196e6bcfa02SGreg Roach        if (Auth::check() && $request->get('route') === 'user-page') {
1970c8c69d4SGreg Roach            return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks');
198ade503dfSGreg Roach        }
199ade503dfSGreg Roach
200e6bcfa02SGreg Roach        if (Auth::isManager($tree) && $request->get('route') === 'tree-page') {
2010c8c69d4SGreg Roach            return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks');
202ade503dfSGreg Roach        }
203ade503dfSGreg Roach
204ade503dfSGreg Roach        return null;
205ade503dfSGreg Roach    }
206ade503dfSGreg Roach
207ade503dfSGreg Roach    /**
208ade503dfSGreg Roach     * Generate a menu item for the control panel.
209ade503dfSGreg Roach     *
2100c8c69d4SGreg Roach     * @param Tree $tree
2110c8c69d4SGreg Roach     *
212ade503dfSGreg Roach     * @return Menu|null
213ade503dfSGreg Roach     */
214e364afe4SGreg Roach    public function menuControlPanel(Tree $tree): ?Menu
215ade503dfSGreg Roach    {
216ade503dfSGreg Roach        if (Auth::isAdmin()) {
217ade503dfSGreg Roach            return new Menu(I18N::translate('Control panel'), route('admin-control-panel'), 'menu-admin');
218ade503dfSGreg Roach        }
219ade503dfSGreg Roach
2200c8c69d4SGreg Roach        if (Auth::isManager($tree)) {
221ade503dfSGreg Roach            return new Menu(I18N::translate('Control panel'), route('admin-control-panel-manager'), 'menu-admin');
222ade503dfSGreg Roach        }
223ade503dfSGreg Roach
224ade503dfSGreg Roach        return null;
225ade503dfSGreg Roach    }
226ade503dfSGreg Roach
227ade503dfSGreg Roach    /**
228ade503dfSGreg Roach     * A menu to show a list of available languages.
229ade503dfSGreg Roach     *
230ade503dfSGreg Roach     * @return Menu|null
231ade503dfSGreg Roach     */
232e364afe4SGreg Roach    public function menuLanguages(): ?Menu
233ade503dfSGreg Roach    {
234ade503dfSGreg Roach        $menu = new Menu(I18N::translate('Language'), '#', 'menu-language');
235ade503dfSGreg Roach
236ade503dfSGreg Roach        foreach (I18N::activeLocales() as $locale) {
237ade503dfSGreg Roach            $language_tag = $locale->languageTag();
238ade503dfSGreg Roach            $class        = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : '');
239ade503dfSGreg Roach            $menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [
240ade503dfSGreg Roach                'onclick'       => 'return false;',
241ade503dfSGreg Roach                'data-language' => $language_tag,
242ade503dfSGreg Roach            ]));
243ade503dfSGreg Roach        }
244ade503dfSGreg Roach
245ade503dfSGreg Roach        if (count($menu->getSubmenus()) > 1) {
246ade503dfSGreg Roach            return $menu;
247ade503dfSGreg Roach        }
248ade503dfSGreg Roach
249ade503dfSGreg Roach        return null;
250ade503dfSGreg Roach    }
251ade503dfSGreg Roach
252ade503dfSGreg Roach    /**
253ade503dfSGreg Roach     * A login menu option (or null if we are already logged in).
254ade503dfSGreg Roach     *
255ade503dfSGreg Roach     * @return Menu|null
256ade503dfSGreg Roach     */
257e364afe4SGreg Roach    public function menuLogin(): ?Menu
258ade503dfSGreg Roach    {
259ade503dfSGreg Roach        if (Auth::check()) {
260ade503dfSGreg Roach            return null;
261ade503dfSGreg Roach        }
262ade503dfSGreg Roach
263ade503dfSGreg Roach        // Return to this page after login...
2646ccdf4f0SGreg Roach        $url = app(ServerRequestInterface::class)->getUri();
265ade503dfSGreg Roach
266ade503dfSGreg Roach        // ...but switch from the tree-page to the user-page
267ade503dfSGreg Roach        $url = str_replace('route=tree-page', 'route=user-page', $url);
268ade503dfSGreg Roach
269ade503dfSGreg Roach        return new Menu(I18N::translate('Sign in'), route('login', ['url' => $url]), 'menu-login', ['rel' => 'nofollow']);
270ade503dfSGreg Roach    }
271ade503dfSGreg Roach
272ade503dfSGreg Roach    /**
273ade503dfSGreg Roach     * A logout menu option (or null if we are already logged out).
274ade503dfSGreg Roach     *
275ade503dfSGreg Roach     * @return Menu|null
276ade503dfSGreg Roach     */
277e364afe4SGreg Roach    public function menuLogout(): ?Menu
278ade503dfSGreg Roach    {
279ade503dfSGreg Roach        if (Auth::check()) {
280ade503dfSGreg Roach            return new Menu(I18N::translate('Sign out'), route('logout'), 'menu-logout');
281ade503dfSGreg Roach        }
282ade503dfSGreg Roach
283ade503dfSGreg Roach        return null;
284ade503dfSGreg Roach    }
285ade503dfSGreg Roach
286ade503dfSGreg Roach    /**
287ade503dfSGreg Roach     * A link to allow users to edit their account settings.
288ade503dfSGreg Roach     *
289ade503dfSGreg Roach     * @return Menu|null
290ade503dfSGreg Roach     */
291e364afe4SGreg Roach    public function menuMyAccount(): ?Menu
292ade503dfSGreg Roach    {
293ade503dfSGreg Roach        if (Auth::check()) {
294ade503dfSGreg Roach            return new Menu(I18N::translate('My account'), route('my-account'));
295ade503dfSGreg Roach        }
296ade503dfSGreg Roach
297ade503dfSGreg Roach        return null;
298ade503dfSGreg Roach    }
299ade503dfSGreg Roach
300ade503dfSGreg Roach    /**
301ade503dfSGreg Roach     * A link to the user's individual record (individual.php).
302ade503dfSGreg Roach     *
3030c8c69d4SGreg Roach     * @param Tree $tree
3040c8c69d4SGreg Roach     *
305ade503dfSGreg Roach     * @return Menu|null
306ade503dfSGreg Roach     */
307e364afe4SGreg Roach    public function menuMyIndividualRecord(Tree $tree): ?Menu
308ade503dfSGreg Roach    {
3090c8c69d4SGreg Roach        $record = Individual::getInstance($tree->getUserPreference(Auth::user(), 'gedcomid'), $tree);
310ade503dfSGreg Roach
311ade503dfSGreg Roach        if ($record) {
312ade503dfSGreg Roach            return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord');
313ade503dfSGreg Roach        }
314ade503dfSGreg Roach
315ade503dfSGreg Roach        return null;
316ade503dfSGreg Roach    }
317ade503dfSGreg Roach
318ade503dfSGreg Roach    /**
319ade503dfSGreg Roach     * A link to the user's personal home page.
320ade503dfSGreg Roach     *
3210c8c69d4SGreg Roach     * @param Tree $tree
3220c8c69d4SGreg Roach     *
323ade503dfSGreg Roach     * @return Menu
324ade503dfSGreg Roach     */
3250c8c69d4SGreg Roach    public function menuMyPage(Tree $tree): Menu
326ade503dfSGreg Roach    {
3270c8c69d4SGreg Roach        return new Menu(I18N::translate('My page'), route('user-page', ['ged' => $tree->name()]), 'menu-mypage');
328ade503dfSGreg Roach    }
329ade503dfSGreg Roach
330ade503dfSGreg Roach    /**
331ade503dfSGreg Roach     * A menu for the user's personal pages.
332ade503dfSGreg Roach     *
3330c8c69d4SGreg Roach     * @param Tree|null $tree
3340c8c69d4SGreg Roach     *
335ade503dfSGreg Roach     * @return Menu|null
336ade503dfSGreg Roach     */
337e364afe4SGreg Roach    public function menuMyPages(?Tree $tree): ?Menu
338ade503dfSGreg Roach    {
3390c8c69d4SGreg Roach        if ($tree instanceof Tree && Auth::id()) {
340ade503dfSGreg Roach            return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([
3410c8c69d4SGreg Roach                $this->menuMyPage($tree),
3420c8c69d4SGreg Roach                $this->menuMyIndividualRecord($tree),
3430c8c69d4SGreg Roach                $this->menuMyPedigree($tree),
344ade503dfSGreg Roach                $this->menuMyAccount(),
3450c8c69d4SGreg Roach                $this->menuControlPanel($tree),
3460c8c69d4SGreg Roach                $this->menuChangeBlocks($tree),
347ade503dfSGreg Roach            ]));
348ade503dfSGreg Roach        }
349ade503dfSGreg Roach
350ade503dfSGreg Roach        return null;
351ade503dfSGreg Roach    }
352ade503dfSGreg Roach
353ade503dfSGreg Roach    /**
354ade503dfSGreg Roach     * A link to the user's individual record.
355ade503dfSGreg Roach     *
3560c8c69d4SGreg Roach     * @param Tree $tree
3570c8c69d4SGreg Roach     *
358ade503dfSGreg Roach     * @return Menu|null
359ade503dfSGreg Roach     */
360e364afe4SGreg Roach    public function menuMyPedigree(Tree $tree): ?Menu
361ade503dfSGreg Roach    {
3620c8c69d4SGreg Roach        $gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid');
363ade503dfSGreg Roach
3640c8c69d4SGreg Roach        $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
3650b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module): bool {
366ade503dfSGreg Roach                return $module instanceof PedigreeChartModule;
367ade503dfSGreg Roach            });
368ade503dfSGreg Roach
369ade503dfSGreg Roach        if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) {
370ade503dfSGreg Roach            return new Menu(
371ade503dfSGreg Roach                I18N::translate('My pedigree'),
372ade503dfSGreg Roach                route('pedigree', [
373ade503dfSGreg Roach                    'xref' => $gedcomid,
3740c8c69d4SGreg Roach                    'ged'  => $tree->name(),
375ade503dfSGreg Roach                ]),
376ade503dfSGreg Roach                'menu-mypedigree'
377ade503dfSGreg Roach            );
378ade503dfSGreg Roach        }
379ade503dfSGreg Roach
380ade503dfSGreg Roach        return null;
381ade503dfSGreg Roach    }
382ade503dfSGreg Roach
383ade503dfSGreg Roach    /**
384ade503dfSGreg Roach     * Create a pending changes menu.
385ade503dfSGreg Roach     *
3860c8c69d4SGreg Roach     * @param Tree|null $tree
3870c8c69d4SGreg Roach     *
388ade503dfSGreg Roach     * @return Menu|null
389ade503dfSGreg Roach     */
390e364afe4SGreg Roach    public function menuPendingChanges(?Tree $tree): ?Menu
391ade503dfSGreg Roach    {
3920c8c69d4SGreg Roach        if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) {
393ade503dfSGreg Roach            $url = route('show-pending', [
3940c8c69d4SGreg Roach                'ged' => $tree->name(),
3956ccdf4f0SGreg Roach                'url' => app(ServerRequestInterface::class)->getUri(),
396ade503dfSGreg Roach            ]);
397ade503dfSGreg Roach
398ade503dfSGreg Roach            return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending');
399ade503dfSGreg Roach        }
400ade503dfSGreg Roach
401ade503dfSGreg Roach        return null;
402ade503dfSGreg Roach    }
403ade503dfSGreg Roach
404ade503dfSGreg Roach    /**
405ade503dfSGreg Roach     * Themes menu.
406ade503dfSGreg Roach     *
407ade503dfSGreg Roach     * @return Menu|null
408ade503dfSGreg Roach     */
409e364afe4SGreg Roach    public function menuThemes(): ?Menu
410ade503dfSGreg Roach    {
411b668782fSGreg Roach        $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true);
412df8baf00SGreg Roach
413cab242e7SGreg Roach        $current_theme = app(ModuleThemeInterface::class);
4148136679eSGreg Roach
4158136679eSGreg Roach        if ($themes->count() > 1) {
4160b5fd0a6SGreg Roach            $submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu {
4178136679eSGreg Roach                $active     = $theme->name() === $current_theme->name();
4188136679eSGreg Roach                $class      = 'menu-theme-' . $theme->name() . ($active ? ' active' : '');
4198136679eSGreg Roach
4208136679eSGreg Roach                return new Menu($theme->title(), '#', $class, [
421ade503dfSGreg Roach                    'onclick'    => 'return false;',
422ade503dfSGreg Roach                    'data-theme' => $theme->name(),
423ade503dfSGreg Roach                ]);
424ade503dfSGreg Roach            });
425ade503dfSGreg Roach
4268136679eSGreg Roach            return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all());
427ade503dfSGreg Roach        }
428ade503dfSGreg Roach
429ade503dfSGreg Roach        return null;
430ade503dfSGreg Roach    }
431ade503dfSGreg Roach
432ade503dfSGreg Roach    /**
433ade503dfSGreg Roach     * Misecellaneous dimensions, fonts, styles, etc.
434ade503dfSGreg Roach     *
435ade503dfSGreg Roach     * @param string $parameter_name
436ade503dfSGreg Roach     *
437ade503dfSGreg Roach     * @return string|int|float
438ade503dfSGreg Roach     */
439ade503dfSGreg Roach    public function parameter($parameter_name)
440ade503dfSGreg Roach    {
441ade503dfSGreg Roach        return '';
442ade503dfSGreg Roach    }
443ade503dfSGreg Roach
444ade503dfSGreg Roach    /**
445ade503dfSGreg Roach     * Generate a list of items for the main menu.
446ade503dfSGreg Roach     *
4470c8c69d4SGreg Roach     * @param Tree|null $tree
4480c8c69d4SGreg Roach     *
449ade503dfSGreg Roach     * @return Menu[]
450ade503dfSGreg Roach     */
4510c8c69d4SGreg Roach    public function genealogyMenu(?Tree $tree): array
452ade503dfSGreg Roach    {
4530c8c69d4SGreg Roach        if ($tree === null) {
4540c8c69d4SGreg Roach            return [];
4550c8c69d4SGreg Roach        }
4560c8c69d4SGreg Roach
4570c8c69d4SGreg Roach        return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user())
4580b5fd0a6SGreg Roach            ->map(static function (ModuleMenuInterface $menu) use ($tree): ?Menu {
4590c8c69d4SGreg Roach                return $menu->getMenu($tree);
460ade503dfSGreg Roach            })
461ade503dfSGreg Roach            ->filter()
462ade503dfSGreg Roach            ->all();
463ade503dfSGreg Roach    }
464ade503dfSGreg Roach
465ade503dfSGreg Roach    /**
4660c8c69d4SGreg Roach     * Create the genealogy menu.
467ade503dfSGreg Roach     *
468ade503dfSGreg Roach     * @param Menu[] $menus
469ade503dfSGreg Roach     *
470ade503dfSGreg Roach     * @return string
471ade503dfSGreg Roach     */
4720c8c69d4SGreg Roach    public function genealogyMenuContent(array $menus): string
473ade503dfSGreg Roach    {
4740b5fd0a6SGreg Roach        return implode('', array_map(static function (Menu $menu): string {
475ade503dfSGreg Roach            return $menu->bootstrap4();
476ade503dfSGreg Roach        }, $menus));
477ade503dfSGreg Roach    }
478ade503dfSGreg Roach
479ade503dfSGreg Roach    /**
480ade503dfSGreg Roach     * Generate a list of items for the user menu.
481ade503dfSGreg Roach     *
4820c8c69d4SGreg Roach     * @param Tree|null $tree
4830c8c69d4SGreg Roach     *
484ade503dfSGreg Roach     * @return Menu[]
485ade503dfSGreg Roach     */
4860c8c69d4SGreg Roach    public function userMenu(?Tree $tree): array
487ade503dfSGreg Roach    {
488ade503dfSGreg Roach        return array_filter([
4890c8c69d4SGreg Roach            $this->menuPendingChanges($tree),
4900c8c69d4SGreg Roach            $this->menuMyPages($tree),
491ade503dfSGreg Roach            $this->menuThemes(),
492ade503dfSGreg Roach            $this->menuLanguages(),
493ade503dfSGreg Roach            $this->menuLogin(),
494ade503dfSGreg Roach            $this->menuLogout(),
495ade503dfSGreg Roach        ]);
496ade503dfSGreg Roach    }
497ade503dfSGreg Roach
498ade503dfSGreg Roach    /**
499ade503dfSGreg Roach     * A list of CSS files to include for this page.
500ade503dfSGreg Roach     *
501ade503dfSGreg Roach     * @return string[]
502ade503dfSGreg Roach     */
503ade503dfSGreg Roach    public function stylesheets(): array
504ade503dfSGreg Roach    {
505ade503dfSGreg Roach        return [];
506ade503dfSGreg Roach    }
50749a243cbSGreg Roach}
508