There are only a few steps involved with creating your own content type for your plugin (or even without a plugin).
Letting CONTENIDO know about the Content Type
The system needs to know which Content Types exist. This is done in the *_type table:
In this table you need to create a new row for your content type.
Choose an idtype that is greater than 100000 to prevent the update process from deleting it.
The columns 'code' and 'status' are not in use currently, so we can create a new row like this:
INSERT INTO `con_type` (`idtype` , `type` , `code` , `description` , `status` , `author` , `created` , `lastmodified` ) VALUES ('100005', 'CMS_NEWTYPE', '', 'This is a new type', '0', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00' );
Which will result in this:
Creating the Content Type class
There are some caveats you have to know about when you create the class for your content type:
- The name of the class must be something like this: "cContentType<Nameofthecontenttype>". In this example the name of the class has to be "cContentTypeNewtype".
- The class must extend cContentTypeAbstract or cContentTypeAbstractTabbed
You want to choose cContentTypeAbstractTabbed if you want to have a menu akin to CMS_LINKEDITOR. For this example we will use the "normal" not-tabbed version. - You have to implemented the generateEditCode() and the generateViewCode() functions
They must return a string which will replace the CMS_NEWTYPE[ID] portion of your module.
Because of these rules the class will look something like this:
class cContentTypeNewtype extends cContentTypeAbstract { public function generateEditCode() { // TODO Add logic return ""; } public function generateViewCode() { // TODO Add logic return ""; } }
Telling CONTENIDO where to find the class
The next step is to tell the CONTENIDO auto loader where this class is located. You can (and should if you're developing a plugin) add code in your config.plugin.php to achieve this (see the cAutoload documentation for more information). Since we're just developing a content type, we'll just add the following line to the config.autoload.local.php.
Modifying the config.autoloader.php might work too, but this file is generated by another program and will definitely be overwritten with a system update!
return array( 'cContentTypeNewtype' => 'contenido/classes/contenttypetest.php'); // you might want to choose a different directory fore your file
Filling the class with logic
After this step your content type is properly registered with CONTENIDO. You can test this by creating a module that uses it and writing some dummy code in the generateEditCode() and the generateViewCode()
<?php echo "CMS_NEWTYPE[1]"; ?>
class cContentTypeNewtype extends cContentTypeAbstract { public function generateEditCode() { return "editing!"; } public function generateViewCode() { return "viewing!"; } }
If everything worked correctly you should see either "editing!" or "viewing!" being outputted:
If that works, you can start implementing the actual logic of your content type.
For further assistance, please take a look at the documentation of cContentTypeAbstract, cContentTypeAbstractTabbed and the content types of the plugins that come with CONTENIDO (User Forum and Form Assistant).
What if it does not work?
Here are some things that might prevent everything from working correctly:
- Make sure that your class file is actually being loaded (you can just add a die() somewhere in the file and see if it actually dies)
- Check the name of your class. It has to follow the pattern described above!
- Make sure that the class is actually extending cContentTypeAbstract
- Check your errorlog for errors
If all of the above seems to be in order you might find someone else to help you on the CONTENIDO forums.