Supported Events
Here is a list of all events generated by Optimus that can be intercepted by addons:
AddonInterface::HOOK_EVENT: Universal event for working with SMF hooksAddonInterface::ROBOTS_RULES: Event for working with therobots.txtrules generatorAddonInterface::SITEMAP_LINKS: Event for adding your own links to the XML sitemapAddonInterface::SITEMAP_CONTENT: Special event for processing the content of the XML sitemap immediately after its structure is formedAddonInterface::SITEMAP_URL_REWRITER: Event for registering a URL rewriter applied to every sitemap link: Deprecated event for processing links in the XML sitemap before its structure is formedAddonInterface::CREATE_SEF_URLS
To implement a connection with the selected event in the addon class, you need to fill in the $events field and create the __invoke method. For example, in the LightPortal addon, it looks like this:
public static array $events = [ self::ROBOTS_RULES, self::SITEMAP_LINKS,];
public function __invoke(AddonEvent $event): void{ match ($event->eventName()) { self::ROBOTS_RULES => $this->changeRobots($event->getTarget()), self::SITEMAP_LINKS => $this->changeSitemap($event->getTarget()), };}Then we create the corresponding methods changeRobots and changeSitemap (you can name them as you wish):
public function changeRobots(RobotsGenerator $generator): void{ var_dump($generator);}
public function changeSitemap(SitemapGenerator $generator): void{ var_dump($generator);}As you can see, the event object self::ROBOTS_RULES passes the RobotsGenerator class for working with the robots.txt generator.
Similarly, the event object self::SITEMAP_LINKS passes the SitemapGenerator class for working with the XML sitemap generator.
And the self::SITEMAP_URL_REWRITER event allows you to register a rewriter for every sitemap link (this is how the SimpleSEF addon works):
public function registerUrlRewriter(SitemapGenerator $generator): void{ $generator->addUrlRewriter(fn(string $url): string => myRewriteFunction($url));}From there, it all depends on your creativity and specific goals. Examples of implementations of built-in addons can be found on GitHub.
If you find the events insufficient or overwhelming, you can alternatively use built-in hooks in Optimus.