xref: /webtrees/app/Module/ModuleBlockInterface.php (revision 1270d2767576ed4a83917769b0ee3613e3b010bf)
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\Tree;
23use Psr\Http\Message\ServerRequestInterface;
24
25/**
26 * Interface ModuleBlockInterface - Classes and libraries for module system
27 */
28interface ModuleBlockInterface extends ModuleInterface
29{
30    // Places we can display blocks
31    public const CONTEXT_EMBED     = 'embed';
32    public const CONTEXT_TREE_PAGE = 'tree';
33    public const CONTEXT_USER_PAGE = 'user';
34
35    // We show blocks in two columns on the tree/user pages.
36    public const MAIN_BLOCKS = 'main';
37    public const SIDE_BLOCKS = 'side';
38
39    public const DEFAULT_TREE_PAGE_BLOCKS = [
40        self::MAIN_BLOCKS => [
41            1 => FamilyTreeStatisticsModule::class,
42            2 => FamilyTreeNewsModule::class,
43            3 => FamilyTreeFavoritesModule::class,
44            4 => ReviewChangesModule::class,
45        ],
46        self::SIDE_BLOCKS => [
47            1 => WelcomeBlockModule::class,
48            2 => SlideShowModule::class,
49            3 => OnThisDayModule::class,
50            4 => LoggedInUsersModule::class,
51        ],
52    ];
53
54    public const DEFAULT_USER_PAGE_BLOCKS = [
55        self::MAIN_BLOCKS => [
56            1 => OnThisDayModule::class,
57            2 => UserMessagesModule::class,
58            3 => UserFavoritesModule::class,
59        ],
60        self::SIDE_BLOCKS => [
61            1 => UserWelcomeModule::class,
62            2 => SlideShowModule::class,
63            3 => UpcomingAnniversariesModule::class,
64            4 => LoggedInUsersModule::class,
65        ],
66    ];
67
68    /**
69     * Generate the HTML content of this block.
70     *
71     * @param Tree                 $tree
72     * @param int                  $block_id
73     * @param string               $context
74     * @param array<string,string> $config
75     *
76     * @return string
77     */
78    public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string;
79
80    /**
81     * Should this block load asynchronously using AJAX?
82     *
83     * Simple blocks are faster in-line, more complex ones can be loaded later.
84     *
85     * @return bool
86     */
87    public function loadAjax(): bool;
88
89    /**
90     * Can this block be shown on the user’s home page?
91     *
92     * @return bool
93     */
94    public function isUserBlock(): bool;
95
96    /**
97     * Can this block be shown on the tree’s home page?
98     *
99     * @return bool
100     */
101    public function isTreeBlock(): bool;
102
103    /**
104     * An HTML form to edit block settings
105     *
106     * @param Tree $tree
107     * @param int  $block_id
108     *
109     * @return string
110     */
111    public function editBlockConfiguration(Tree $tree, int $block_id): string;
112
113    /**
114     * Update the configuration for a block.
115     *
116     * @param ServerRequestInterface $request
117     * @param int     $block_id
118     *
119     * @return void
120     */
121    public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void;
122}
123