xref: /webtrees/app/Module/ModuleBlockTrait.php (revision 8b02deb402ba1463d59186bc5b8a6500aeb32318)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Module;
19
20use Fisharebest\Webtrees\Auth;
21use Fisharebest\Webtrees\Tree;
22use Psr\Http\Message\ServerRequestInterface;
23use function route;
24
25/**
26 * Trait ModuleBlockTrait - default implementation of ModuleBlockInterface
27 */
28trait ModuleBlockTrait
29{
30    /**
31     * @param Tree   $tree
32     * @param string $context
33     * @param int    $block_id
34     *
35     * @return string
36     */
37    protected function configUrl(Tree $tree, string $context, int $block_id): string
38    {
39        if ($context === self::CONTEXT_TREE_PAGE && Auth::isManager($tree)) {
40            return route('tree-page-block-edit', [
41                'block_id' => $block_id,
42                'ged'      => $tree->name(),
43            ]);
44        }
45
46        if ($context === self::CONTEXT_USER_PAGE && Auth::check()) {
47            return route('user-page-block-edit', [
48                'block_id' => $block_id,
49                'ged'      => $tree->name(),
50            ]);
51        }
52
53        return '';
54    }
55
56    /**
57     * Update the configuration for a block.
58     *
59     * @param ServerRequestInterface $request
60     * @param int                    $block_id
61     *
62     * @return void
63     */
64    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
65    {
66    }
67
68    /**
69     * An HTML form to edit block settings
70     *
71     * @param Tree $tree
72     * @param int  $block_id
73     *
74     * @return string
75     */
76    public function editBlockConfiguration(Tree $tree, int $block_id): string
77    {
78        return '';
79    }
80}
81