Issue with Event Listener Not Being Triggered in My Plugin

Hi,

I am currently working on a plugin and have come across an issue where an event listener I registered in the boot method of my plugin class is not being triggered as expected. Here’s a snippet of the relevant code in my Plugin.php file:

public function boot()
{
    $this->bootLscache();
    Event::listen('backend.form.extendFieldsBefore', function ($widget) {
        Log::info('backend.form.extendFields event triggered');
        // Only extend if it is the CMS Page model
        if (!$widget->model instanceof \Cms\Classes\Page) {
            Log::info('Model is not an instance of Cms\Classes\Page');
            return;
        }
        $widget->addTabFields([
            'lscache[url_path]' => [
                'label' => 'Path of page',
                'tab' => 'Cache Settings',
                'type' => 'dropdown',
                'options' => $this->getPageOptions(),
            ],
            'lscache[max_age]' => [
                'label' => 'Max-age',
                'tab' => 'Cache Settings',
                'type' => 'text',
            ],
            'lscache[lscache]' => [
                'label' => 'Type of cache',
                'tab' => 'Cache Settings',
                'type' => 'dropdown',
                'options' => [
                    'public' => 'public',
                    'no-cache' => 'no-cache',
                    'private' => 'private',
                ],
            ],
        ]);
    });
}

The event backend.form.extendFieldsBefore is supposed to be triggered when the backend form fields are being extended before rendering. However, the event listener never seems to be executed, and the log statement within the event listener does not show up in my log files.

I have verified that my plugin is registered and activated correctly in OctoberCMS. I also checked the spelling of the event name and ensured that the check for the model class is correct.

Try using dd() to “dump and die” within your event listener. It will halt the process and can give some more insight.