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