emerico
7/8/2016 - 8:54 AM

How to add ckeditor / wysiwyg editor in category description field in expression engine.

How to add ckeditor / wysiwyg editor in category description field in expression engine.

<?php
/*
* HOW TO:-
* Here is simple accessories code for adding ckeditor / wysiwyg editor in category description field in expression engine.
* create a directory as /system/expressionengine/third_party/eme_utills
* create a accessories addon file like /system/expressionengine/third_party/eme_utills/acc.eme_utills.php
* Now add the following code to it
*/
/**
 * EME UTILLS Accessory
 * Class EME_Utills_acc
 * @package     EME_Utills
 * @category    Accessory
 * @description Admin Modification
 * @author      Udit Rawat
 * @link        http://emerico.in
 */
class EME_Utills_acc
{
    var $name = 'EME UTILLS Accessory';
    var $id = 'eme_utills_acc';
    var $version = '1.0';
    var $description = 'Add wysiwyg editor to category description field By <a target="_blank" href="http://emerico.in">Emerico Web Solutions</a>';
    var $sections = array();

    /**
     * Constructor
     */
    public function EME_Utills_acc()
    {
        $this->EE =& get_instance();
    }

    /**
     * Section code
     */
    public function set_sections()
    {
        $category_slug = $this->EE->uri->segment(3, 0); //category_edit
        $category_id = intval($this->EE->input->get('cat_id'));

        $this->sections[] = '<script type="text/javascript" charset="utf-8">$("#accessoryTabs a.eme_utills_acc").parent().remove();</script>';
        if($category_slug == 'category_edit' && $category_id > 0) {
            ee()->cp->add_to_foot('
            <script src="//cdn.ckeditor.com/4.5.9/standard/ckeditor.js"></script>
            <script type="text/javascript">
                CKEDITOR.config.height = 150;
                CKEDITOR.config.width = \'auto\';
                CKEDITOR.config.uiColor = \'#ECF1F4\';
                CKEDITOR.config.extraAllowedContent = \'div(*)\';
                CKEDITOR.replace( \'cat_description\' );
             </script>
            ');
        }
    }
}