Jump to content

Add custom field to CMS module.


ludo.big.youth

Recommended Posts

Hi all.

Here is the thing :

 

Under Tools -> CMS, i'm creating a Designers category, and inside this category, i've got a lot of Designer's pages.

 

I would like to add an upload image field, so i can upload a logo for each designer.

And i don't want to upload the logo into the rich text editor.

 

Any idea on how to do this ?

 

Have a good day.

 

Ludo

Link to comment
Share on other sites

  • 5 months later...
  • 6 months later...

Hi.

 

You can not override that controller, you need to overwrite it.

 

You need to add a new field to $this->fields_form in the function renderForm() and set the $this->fieldImageSettings property in the constructor (also create the folder and table column for it). A good example is AdminCategoriesController.php

 

This should do the trick. ;)

 

Regards.

 

Robin.

 

The CartExpert Team

Link to comment
Share on other sites

I think it's posible override. because it's working in my locahost B)

first override classes/CMS.php

class CMS extends CMSCore
{
public $yourfield; // <--------------------------------------------------

/**
 * @see ObjectModel::$definition
 */
public static $definition = array(
 'table' => 'cms',
 'primary' => 'id_cms',
 'multilang' => true,
 'fields' => array(
  'id_cms_category' =>  array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
  'position' =>    array('type' => self::TYPE_INT),
  'active' =>    array('type' => self::TYPE_BOOL),
  // Lang fields
  '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),
  'meta_title' =>   array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
  'content' =>    array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999),
  'yourfield' =>   array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'size' => 3999999999999),  ),// <-- and your desired properties
);
}

 

next override controllers/admin/

 

<?php
class AdminCmsController extends AdminCmsControllerCore
{
public function renderForm()
{
 $this->display = 'edit';
 $this->toolbar_btn['save-and-preview'] = array(
  'href' => '#',
  'desc' => $this->l('Save and preview')
 );
 $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_cms_category'), 1);
 $this->fields_form = array(
  'tinymce' => true,
  'legend' => array(
   'title' => $this->l('CMS Page'),
   'image' => '../img/admin/tab-categories.gif'
  ),
  'input' => array(
   // custom template
   array(
 'type' => 'select_category',
 'label' => $this->l('CMS Category'),
 'name' => 'id_cms_category',
 'options' => array(
  'html' => $html_categories,
 ),
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Meta title:'),
 'name' => 'meta_title',
 'id' => 'name', // for copy2friendlyUrl compatibility
 'lang' => true,
 'required' => true,
 'class' => 'copy2friendlyUrl',
 'hint' => $this->l('Invalid characters:').' <>;=#{}',
 'size' => 50
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Meta description'),
 'name' => 'meta_description',
 'lang' => true,
 'hint' => $this->l('Invalid characters:').' <>;=#{}',
 'size' => 70
   ),
   array(
 'type' => 'tags',
 'label' => $this->l('Meta keywords'),
 'name' => 'meta_keywords',
 'lang' => true,
 'hint' => $this->l('Invalid characters:').' <>;=#{}',
 'size' => 70,
 'desc' => $this->l('To add "tags" click in the field, write something, then press "Enter"')
   ),
   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')
   ),
   array(
 'type' => 'textarea',
 'label' => $this->l('Page content'),
 'name' => 'content',
 'autoload_rte' => true,
 'lang' => true,
 'rows' => 5,
 'cols' => 40,
 'hint' => $this->l('Invalid characters:').' <>;=#{}'
   ),
array(//<------------------------------------------------------------------------- your field
 'type' => 'text',
 'label' => $this->l('your field'),
 'name' => 'yourfield', //<--------------------------------------------------same name as CMS.php ofcourse
 'required' => true,
 'lang' => true,
 'hint' => $this->l('Only letters and the minus (-) character are allowed')
   ),//<--------------------------------------------------------------------------- end your field
   array(
 'type' => 'radio',
 'label' => $this->l('Displayed:'),
 'name' => 'active',
 'required' => false,
 'class' => 't',
 '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')
  )
 ),
   ),
  ),
  'submit' => array(
   'title' => $this->l('   Save   '),
   'class' => 'button'
  )
 );
 if (Shop::isFeatureActive())
 {
  $this->fields_form['input'][] = array(
   'type' => 'shop',
   'label' => $this->l('Shop association:'),
   'name' => 'checkBoxShopAsso',
  );
 }
 $this->tpl_form_vars = array(
  'active' => $this->object->active
 );
 return AdminControllerCore::renderForm();//<----------------------------- Use this... not use parent
}
}

 

Then you must create the field needed in database in table ps_cms_lang your fieldname (used as variable in CMS.php and controlleradmin) is the name of the field in DB

At this moment i don't know how to do this inside php sorry.. you must know how to create db fields

 

and then it's only chage themes/yourtheme/cms.tpl with your new and shining custom fields

 

investigatión cost: 2coffee+ 6 hours + 1/8 brain deceased XD

 

i hope this is usefull for somebody

  • Like 2
  • Thanks 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...