|
| 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 | +}; |
0 commit comments