xref: /webtrees/app/Module/ModuleBlockTrait.php (revision 5afbc57a5c33b9caec67458db57f44e54a90f745)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\Module;
20
21use Fisharebest\Webtrees\Auth;
22use Fisharebest\Webtrees\Tree;
23use Psr\Http\Message\ServerRequestInterface;
24
25use function route;
26
27/**
28 * Trait ModuleBlockTrait - default implementation of ModuleBlockInterface
29 */
30trait ModuleBlockTrait
31{
32    /**
33     * @param Tree   $tree
34     * @param string $context
35     * @param int    $block_id
36     *
37     * @return string
38     */
39    protected function configUrl(Tree $tree, string $context, int $block_id): string
40    {
41        if ($context === self::CONTEXT_TREE_PAGE && Auth::isManager($tree)) {
42            return route('tree-page-block-edit', [
43                'block_id' => $block_id,
44                'tree'     => $tree->name(),
45            ]);
46        }
47
48        if ($context === self::CONTEXT_USER_PAGE && Auth::check()) {
49            return route('user-page-block-edit', [
50                'block_id' => $block_id,
51                'tree'     => $tree->name(),
52            ]);
53        }
54
55        return '';
56    }
57
58    /**
59     * Update the configuration for a block.
60     *
61     * @param ServerRequestInterface $request
62     * @param int                    $block_id
63     *
64     * @return void
65     */
66    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void
67    {
68    }
69
70    /**
71     * An HTML form to edit block settings
72     *
73     * @param Tree $tree
74     * @param int  $block_id
75     *
76     * @return string
77     */
78    public function editBlockConfiguration(Tree $tree, int $block_id): string
79    {
80        return '';
81    }
82}
83