Skip to content

Commit c1c60be

Browse files
committed
Initial commit
0 parents  commit c1c60be

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

ExampleModuleCustomTags.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# EXAMPLE MODULE
2+
3+
This example shows how to create and use custom tags.
4+
5+
All the functions are optional - edit the ones you need, and
6+
delete those that you do not need.
7+
8+
For example, the functions regarding versions, author, support,
9+
etc. are only relevant for modules that you intend to share publicly.
10+
11+
For sub-tags, the codes `0:1`, `1:M`, etc. show the minimum
12+
and maximum number of occurrences. When setting sub-tags, you
13+
can use `0:0` to remove an existing sub-tag.

latest-version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

module.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* Example module.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace ExampleNamespace;
10+
11+
require __DIR__ . '/ExampleModuleCustomTags.php';
12+
13+
// This script must return an object that implements ModuleCustomInterface.
14+
// If the module's constructor does not take any parameters, you can simply instantiate it.
15+
//
16+
// If you are using dependency-injection in your module, you would ask webtrees to make the object for you.
17+
// return Webtrees::make(ExampleModule::class);
18+
// For an example, see the server-config module.
19+
20+
return new ExampleModuleCustomTags();

0 commit comments

Comments
 (0)