Jump to content

TinyMCE in CMS Category description in 1.6


cedced

Recommended Posts

Hi,

 

I've managed to have the TinyMCE attached to the CMS Category and when I use it to format the text it works fine. However when I save the page, nothing is saved : the formatting doesn't show on the frontend and if I edit back the cms category page, although TinyMCE is still there, the formatting is reset.

 

Has anyone put in place TinyCME for the CMS category description or would know what to correct for the formatting to be saved?

 

Thanks

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 3 months later...

Prestashop 1.6.1.2

 

1. Add TinyMCE editor to cms category description field

'autoload_rte' => true

create overriding file /override/controllers/admin/AdminCmsCategoriesController.php

<?php


Class AdminCmsCategoriesController extends AdminCmsCategoriesControllerCore
{
    public function renderForm()
    {
        $this->display = 'edit';
        $this->initToolbar();
        if (!$this->loadObject(true)) {
            return;
        }


        $categories = CMSCategory::getCategories($this->context->language->id, false);
        $html_categories = CMSCategory::recurseCMSCategory($categories, $categories[0][1], 1, $this->getFieldValue($this->object, 'id_parent'), 1);


        $this->fields_form = array(
            'legend' => array(
                'title' => $this->l('CMS Category'),
                'icon' => 'icon-folder-close'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Name'),
                    'name' => 'name',
                    'required' => true,
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}'
                ),
                array(
                    'type' => 'switch',
                    'label' => $this->l('Displayed'),
                    'name' => 'active',
                    'required' => false,
                    'is_bool' => true,
                    'values' => array(
                        array(
                            'id' => 'active_on',
                            'value' => 1,
                            'label' => $this->l('Enabled')
                        ),
                        array(
                            'id' => 'active_off',
                            'value' => 0,
                            'label' => $this->l('Disabled')
                        )
                    ),
                ),
                // custom template
                array(
                    'type' => 'select_category',
                    'label' => $this->l('Parent CMS Category'),
                    'name' => 'id_parent',
                    'options' => array(
                        'html' => $html_categories,
                    ),
                ),
                array(
                    'type' => 'textarea',
                    'label' => $this->l('Description'),
                    'name' => 'description',
                    'lang' => true,
                    'rows' => 5,
                    'cols' => 40,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
'autoload_rte' => true
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta title'),
                    'name' => 'meta_title',
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}'
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta description'),
                    'name' => 'meta_description',
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}'
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta keywords'),
                    'name' => 'meta_keywords',
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}'
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Friendly URL'),
                    'name' => 'link_rewrite',
                    'required' => true,
                    'lang' => true,
                    'hint' => $this->l('Only letters and the minus (-) character are allowed.')
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
            )
        );


        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array(
                'type' => 'shop',
                'label' => $this->l('Shop association'),
                'name' => 'checkBoxShopAsso',
            );
        }


        $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
        return AdminController::renderForm();
    }
}
?>

2. Let the prestashop save html code, replacing cms category desription field type from 

TYPE_STRING

to 

TYPE_HTML

create overriding file /override/classes/CMSCategory.php

<?php


class CMSCategory extends CMSCategoryCore
{
    public static $definition = array(
        'table' => 'cms_category',
        'primary' => 'id_cms_category',
        'multilang' => true,
        'multilang_shop' => true,
        'fields' => array(
            'active' =>            array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
            'id_parent' =>            array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
            'position' =>            array('type' => self::TYPE_INT),
            'level_depth' =>        array('type' => self::TYPE_INT),
            'date_add' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
            'date_upd' =>            array('type' => self::TYPE_DATE, 'validate' => 'isDate'),


            /* Lang fields */
            'name' =>                array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
            'link_rewrite' =>        array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64),
            'description' =>        array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
            'meta_title' =>        array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
            'meta_description' =>    array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
            'meta_keywords' =>        array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
        ),
    ); 
}


?>

3.Go to your theme folder, open cms.tpl, find 

<p>{$cms_category->description|escape:'html':'UTF-8'}</p>

replace to

<div>{$cms_category->description}</div>

4. Dont forget to delete class_index.php in the /cache folder

Edited by vadimda (see edit history)
  • Like 5
Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

Hi everyone,

 

I am glad somebody could fix this for PS 1.6.1.4.

I also need to have tinymce and html code in Category description. Could someone teach me how to do it, please?

 

Thanks in advance.

Adrian.

 

P.S. My first instict is to copy the solution for CMS category description and just delete the "CMS" out of it... Will that work or is there a different approach?

Edited by motorevolution (see edit history)
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...