This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

linard.koning64281
linard.koning64281

Hallo,

I hope somebody can help me out a little. Im new to this CMS but i really like it so far. Im trying to write a plugin to alter CMS pages part a little.

The aim is to add an image field to page so when im making page I can add an header to a page without having to go to another plugin to do this. I tried following the documentation of octoberCMS but i get an error on Event::listen

Class 'Linardkoning\Featuredheaders\Event' not found

C:\xampp\htdocs\linardkoning.me\plugins\linardkoning\featuredheaders\Plugin.php line 22

Forgive me if this is all very new to me. I wrote the following code:

<?php namespace Linardkoning\Featuredheaders;

use Backend;
use System\Classes\PluginBase;

class Plugin extends PluginBase
{

    public function pluginDetails()
    {
        return [
            'name'        => 'featuredheaders',
            'description' => 'Plugin to have header image in CMS Page',
            'author'      => 'linardkoning',
            'icon'        => 'icon-leaf'
        ];
    }

    public function boot()
    {
        // Extend all backend form usage
        Event::listen('backend.form.extendFields', function($widget) {

            // Only for the User model
            if (!$widget->model instanceof \Cms\Classes\Page) {
                return;
            }

            // Add an extra birthday field
            $widget->addTabFields([
                'header' => [
                    'label'     => 'header',
                    'tab'       => 'Header',
                    'type'      => 'fileupload',
                    'mode'      => 'image',
                ]
            ]);
        });
    }
}
Eoler
Eoler

linard.koning64281 said: I tried following the documentation of octoberCMS but i get an error on Event::listen Class 'Linardkoning\Featuredheaders\Event' not found

Add use Event; before class definition.

linard.koning64281
linard.koning64281

Thanks for the help that worked. Also noticed I needed to replace function boot with function register.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.