Add-On Development with Add-on Controllers

New to ExpressionEngine 6.4 and 7.2, EEObjects is a new way to organize add-on code, automatically routing actions, tags, extension hooks, and control panel routes into their own logical classes. This allows for cleaner, more readable add-on code, and an officially supported way to build add-ons moving forward. This was a community-driven update from Eric Lamb (mithra62), so HUGE shout out to him for spearheading it! 

How to use it? 

Extension hooks can now be organized into a single file per hook. Create an Extensions folder in your add-on folder, and then create a file for your extension hook. The name of this file should be in PascalCase, and should be the name of the hook method you are replacing. Here is an example of what that would look like:

<?php

namespace AddonDev\ExampleAddon\Extensions;

use ExpressionEngine\Service\Addon\Controllers\Extension\AbstractRoute;

class SessionsStart extends AbstractRoute
{
    public function process()
    {
        // Run extension hook here
    }
}

This is an example of the sessions_start hook, and in this example, when the hook fires, the process() function will run. To get the extension to actually start using these hooks, the ext file needs to extend the ExpressionEngine\Service\Addon\Extension class and define the $addon_name protected property as the add-on shortname.

Comments 0

Be the first to comment!