Skip to content

Commit b46cf05

Browse files
committed
Initial commit
0 parents  commit b46cf05

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

ExampleModuleTheme.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* Example theme. Here we are extending an existing theme.
5+
* Instead, you could extend AbstractModule and implement ModuleThemeInterface directly.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ExampleNamespace;
11+
12+
use Fisharebest\Webtrees\Module\MinimalTheme;
13+
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
14+
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
15+
use Fisharebest\Webtrees\View;
16+
17+
class ExampleModuleTheme extends MinimalTheme implements ModuleCustomInterface {
18+
use ModuleCustomTrait;
19+
20+
/**
21+
* @return string
22+
*/
23+
public function title(): string
24+
{
25+
return 'Example module';
26+
}
27+
28+
/**
29+
* Bootstrap the module
30+
*/
31+
public function boot(): void
32+
{
33+
// Register a namespace for our views.
34+
View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
35+
36+
// Replace an existing view with our own version.
37+
View::registerCustomView('::chart-box', $this->name() . '::chart-box');
38+
}
39+
40+
/**
41+
* Where does this module store its resources
42+
*
43+
* @return string
44+
*/
45+
public function resourcesFolder(): string
46+
{
47+
return __DIR__ . '/resources/';
48+
}
49+
50+
/**
51+
* Add our own stylesheet to the existing stylesheets.
52+
*
53+
* @return array<string>
54+
*/
55+
public function stylesheets(): array
56+
{
57+
$stylesheets = parent::stylesheets();
58+
59+
// NOTE - a future version of webtrees will allow the modules to be stored in a private folder.
60+
// Only files in the /public/ folder will be accessible via the webserver.
61+
// Since modules cannot copy their files to the /public/ folder, they need to provide them via a callback.
62+
$stylesheets[] = $this->assetUrl('css/theme.css');
63+
64+
return $stylesheets;
65+
}
66+
};

module.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/**
4+
* Example theme.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace ExampleNamespace;
10+
11+
require __DIR__ . '/ExampleModuleTheme.php';
12+
13+
return new ExampleModuleTheme();

resources/css/theme.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body.wt-global {
2+
color: orange;
3+
}

resources/views/chart-box.phtml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- A nice orange border around the existing chart box -->
2+
<div style="outline: dashed thick orange">
3+
<!-- The "::" allows us to use the original view, without being redirected to this file. -->
4+
<?= view('::chart-box', ['individual' => $individual]) ?>
5+
</div>

0 commit comments

Comments
 (0)