Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Extending an existing formwidget.

0
by mjauvin, last modified on July 19th, 2024
<?php namespace StudioAzura\Foundation\FormWidgets;

use Backend\FormWidgets\RichEditor;

class RichEditorPlus extends RichEditor
{
    protected $defaultAlias = 'rich-editor-plus';

    public function init()
    {
        // set the parent's viewPath so that its partials can be found.
        $this->addViewPath('~/modules/backend/formwidgets/richeditor/partials');
        parent::init();
    }

    protected function loadAssets()
    {   
        $savedAssetPath = $this->assetPath;

        // set the parent's assetPath so that its assets can be found.
        $this->assetPath = '/modules/backend/formwidgets/richeditor/assets';
        parent::loadAssets();

        // reset our own assetPath
        $this->assetPath = $savedAssetPath;
        $this->addJs('js/richeditorplus.js');
    }
}

And you need to register the new formwidget:

public function registerFormWidgets()
{   
    return [
        FormWidgets\RichEditorPlus::class => 'richeditorplus',
    ];
}

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?