Skip to content

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 hooks
  • AddonInterface::ROBOTS_RULES: Event for working with the robots.txt rules generator
  • AddonInterface::SITEMAP_LINKS: Event for working with the XML sitemap generator
  • AddonInterface::SITEMAP_CONTENT: Special event for processing the content of the XML sitemap immediately after its structure is formed
  • AddonInterface::CREATE_SEF_URLS: Special event for processing links in the XML sitemap before its structure is formed

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 $robots): void
{
var_dump($robots);
}
public function changeSitemap(SitemapGenerator $sitemap): void
{
var_dump($sitemap);
}

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.

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.