. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Fact; use Fisharebest\Webtrees\I18N; use function e; /** * Trait ModuleMapLinkTrait - default implementation of ModuleMapLinkInterface */ trait ModuleMapLinkTrait { /** * How should this module be identified in the control panel, etc.? * * @return string */ public function title(): string { return $this->providerName() . ' — ' . I18N::translate('Map link'); } public function description(): string { return I18N::translate('Show the location of an event on an external map.'); } /** * @param Fact $fact * * @return string */ public function mapLink(Fact $fact): string { if ($this->isMapAvailableForLocation($fact)) { $icon = $this->icon(); $url = $this->mapUrl($fact); $title = I18N::translate('View this location using %s', $this->providerName()); return '' . $icon . ''; } return ''; } /** * Name of the map provider. * * @return string */ protected function providerName(): string { return 'example.com'; } /** * @param Fact $fact * * @return bool */ protected function isMapAvailableForLocation(Fact $fact): bool { return $fact->latitude() !== null && $fact->longitude() !== null; } /** * @return string */ protected function icon(): string { return 'icon'; } /** * @param Fact $fact * * @return string */ protected function mapUrl(Fact $fact): string { return 'https://example.com'; } }