Back to CKeditor Support

Flynsarmy
Flynsarmy

I whipped up quick plugin to automatically show content fields as WYSIWYG. This will survive through updates.

Simply php artisan create:plugin Flynsarmy.WYSIWYGContent and in the /plugins/flynsarmy/wysiwygcontent/Plugin.php file drop

public function boot()
{
    Event::listen('backend.form.extendFields', function($form) {
        // Only apply changes to Cms\Classes\Content form
        if ( empty($form->config->model) ||
             !is_object($form->config->model) ||
             get_class($form->config->model) != 'Cms\Classes\Content' )
            return;

        foreach ($form->allFields as $field )
        {
            // Only apply changes to codeeditor fields
            if ( empty($field->config['type']) || $field->config['type'] != 'codeeditor' )
                continue;

            $field->config['type'] = $field->config['widget'] = 'ShahiemSeymor\Ckeditor\FormWidgets\Wysiwyg';
            // $field->config['type'] = $field->config['widget'] = 'Eein\Wysiwyg\FormWidgets\Trumbowyg';
        }
    });
}

Last updated

webasc1915
webasc1915

I dropped it, but I have an error:

We're sorry, but an unhandled error occurred. Please see the details below. Class 'Flynsarmy\WYSIWYGContent\Event' not found /.../plugins/flynsarmy/wysiwygcontent/Plugin.php line 29 Type Undefined Exception Symfony\Component\Debug\Exception\FatalErrorException public function boot() {

Event::listen('backend.form.extendFields', function($form) {
// Only apply changes to Cms\Classes\Content form
    if ( empty($form->config->model) || !is_object($form->config->model) || get_class($form->config->model) != 'Cms\Classes\Content' )
    return;

foreach ($form->allFields as $field )
    {

Stack trace

Called Code Document Line

1 Illuminate\Exception\Handler->handleShutdown()

what should I do? thanks

Last updated

kasper1801
kasper1801

First of all thanks for sharing the code @Flynsarmy! Have created a plugin that does something similare, but in a new view and not in the normal content view. This is much better! Could be nice if there could be crated some type of page showing all the events you can hook into. This will make it allot easier to get an overview of what happens when.

Reagarding your issue @websac1915, I think your problem is that you havent added the correct Event class in your use definition at the top of the file. Try adding ´use Event;´ and see if it helps :)

Flynsarmy
Flynsarmy

kasper is right. Add use Event; at the top. My bad.

Kasper, you can get a list of supported events by cding into october's root directory and typing find . -name "*.php" -exec grep -Hn "Event::fire" {} \; but I agree, a docs page would be much nicer.

Last updated

webasc1915
webasc1915

Thanks a lot. It's working now :)

Flynsarmy
Flynsarmy

For anyone still interested in this, I've just made a pull request here that adds a settings page with checkbox. Hopefully @Shahiem will add it to the next version of the plugin.

Shahiem
Shahiem

Thank you Flyn ;) Check out the new update.

1-7 of 7