|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Example module. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace ExampleNamespace; |
| 10 | + |
| 11 | +use Fisharebest\Webtrees\Contracts\ElementInterface; |
| 12 | +use Fisharebest\Webtrees\Elements\AddressWebPage; |
| 13 | +use Fisharebest\Webtrees\Elements\CustomElement; |
| 14 | +use Fisharebest\Webtrees\Elements\EmptyElement; |
| 15 | +use Fisharebest\Webtrees\Elements\NameOfRepository; |
| 16 | +use Fisharebest\Webtrees\Elements\SourceDescriptiveTitle; |
| 17 | +use Fisharebest\Webtrees\Elements\SubmitterText; |
| 18 | +use Fisharebest\Webtrees\I18N; |
| 19 | +use Fisharebest\Webtrees\Module\AbstractModule; |
| 20 | +use Fisharebest\Webtrees\Module\ModuleCustomInterface; |
| 21 | +use Fisharebest\Webtrees\Module\ModuleCustomTagsInterface; |
| 22 | +use Fisharebest\Webtrees\Module\ModuleCustomTagsTrait; |
| 23 | +use Fisharebest\Webtrees\Module\ModuleCustomTrait; |
| 24 | + |
| 25 | +/** |
| 26 | + * Class ExampleModuleCustomTags |
| 27 | + * |
| 28 | + * This example shows how to create a custom module. |
| 29 | + * All the functions are optional. Just implement the ones you need. |
| 30 | + * |
| 31 | + * Modules *must* implement ModuleCustomInterface. They *may* also implement other interfaces. |
| 32 | + */ |
| 33 | +class ExampleModuleCustomTags extends AbstractModule implements ModuleCustomTagsInterface, ModuleCustomInterface |
| 34 | +{ |
| 35 | + // For every module interface that is implemented, the corresponding trait *should* also use be used. |
| 36 | + use ModuleCustomTrait; |
| 37 | + use ModuleCustomTagsTrait; |
| 38 | + |
| 39 | + /** |
| 40 | + * How should this module be identified in the control panel, etc.? |
| 41 | + * |
| 42 | + * @return string |
| 43 | + */ |
| 44 | + public function title(): string |
| 45 | + { |
| 46 | + return I18N::translate('Custom tags'); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * A sentence describing what this module does. |
| 51 | + * |
| 52 | + * @return string |
| 53 | + */ |
| 54 | + public function description(): string |
| 55 | + { |
| 56 | + return I18N::translate('This module provides some custom tags'); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * The person or organisation who created this module. |
| 61 | + * |
| 62 | + * @return string |
| 63 | + */ |
| 64 | + public function customModuleAuthorName(): string |
| 65 | + { |
| 66 | + return 'Greg Roach'; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * The version of this module. |
| 71 | + * |
| 72 | + * @return string |
| 73 | + */ |
| 74 | + public function customModuleVersion(): string |
| 75 | + { |
| 76 | + return '1.0.0'; |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * A URL that will provide the latest version of this module. |
| 81 | + * |
| 82 | + * @return string |
| 83 | + */ |
| 84 | + public function customModuleLatestVersionUrl(): string |
| 85 | + { |
| 86 | + return 'https://github.com/webtrees/example-module-custom-tags/raw/main/latest-version.txt'; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Where to get support for this module. Perhaps a github repository? |
| 91 | + * |
| 92 | + * @return string |
| 93 | + */ |
| 94 | + public function customModuleSupportUrl(): string |
| 95 | + { |
| 96 | + return 'https://github.com/webtrees/example-module-custom-tags'; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Additional/updated translations. |
| 101 | + * |
| 102 | + * @param string $language |
| 103 | + * |
| 104 | + * @return array<string> |
| 105 | + */ |
| 106 | + public function customTranslations(string $language): array |
| 107 | + { |
| 108 | + switch ($language) { |
| 109 | + case 'fr': |
| 110 | + case 'fr-CA': |
| 111 | + return [ |
| 112 | + 'Mother tongue' => 'Langue maternelle', |
| 113 | + ]; |
| 114 | + |
| 115 | + default: |
| 116 | + return []; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * @return array<string,ElementInterface> |
| 122 | + */ |
| 123 | + public function customTags(): array |
| 124 | + { |
| 125 | + return [ |
| 126 | + 'FAM:DATA' => new EmptyElement(I18N::translate('Data'), ['TEXT' => '0:1']), |
| 127 | + 'FAM:TEXT' => new SubmitterText(I18N::translate('Text')), |
| 128 | + 'INDI:COMM' => new CustomElement(I18N::translate('Comment'), ['URL' => '0:1']), |
| 129 | + 'INDI:COMM:URL' => new AddressWebPage(I18N::translate('URL')), |
| 130 | + 'INDI:DATA' => new EmptyElement(I18N::translate('Data'), ['TEXT' => '0:1']), |
| 131 | + 'INDI:DATA:TEXT' => new SubmitterText(I18N::translate('Text')), |
| 132 | + 'INDI:_MTNG' => new CustomElement(I18N::translate('Mother tongue')), |
| 133 | + 'SOUR:AUTH:NOTE' => new SubmitterText(I18N::translate('Note')), |
| 134 | + 'REPO:NAME:_HEB' => new NameOfRepository(I18N::translate('Hebrew name')), |
| 135 | + 'SOUR:TITL:_HEB' => new SourceDescriptiveTitle(I18N::translate('Hebrew title')), |
| 136 | + ]; |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * @return array<string,array<int,array<int,string>>> |
| 141 | + */ |
| 142 | + public function customSubTags(): array |
| 143 | + { |
| 144 | + return [ |
| 145 | + 'FAM' => [['DATA', '0:M']], |
| 146 | + 'INDI' => [['_MTNG', '0:1'], ['COMM', '0:M'], ['DATA', '0:M']], |
| 147 | + 'REPO:NAME' => [['_HEB', '0:1']], |
| 148 | + 'SOUR:TITL' => [['_HEB', '0:1']], |
| 149 | + ]; |
| 150 | + } |
| 151 | +} |
0 commit comments