You are here: php » (solution) joomla 1 5 add parameter to content component in joomla (com content)
[SOLUTION] Joomla 1.5 Add parameter to Content Component in Joomla (com_content)
- Written By
- PHPin24
- Submitted At
- 2010-10-26 10:45:34
- Num Views
- 941
- Category
- PHP
|
For the sake of this example we will be adding an "is featured" to the article / content component of joomla. This will help you to add an is_featured section to your joomla content / article component 1. Add a parameter in administrator/components/com_content/models/article.xml If you look in the file at line 4 it will have the following <params addpath="/administrator/components/com_content/elements"> <param name="created_by" type="author" default="" label="Author" description="DETAILAUTHOR" /> <param name="created_by_alias" type="text" size="20" default="" label="Author Alias" description="DETAILAUTHORALIAS" /> <param name="access" type="list" size="20" default="0" label="Access Level" description="DETAILACCESS"> <option value="0">Public</option> <option value="1">Registered</option> <option value="2">Special</option> </param> <param name="created" type="calendar" default="" label="Created Date" description="DETAILCREATED" /> <param name="publish_up" type="calendar" default="" label="Start Publishing" description="DETAILSTART" /> <param name="publish_down" type="calendar" default="" label="Finish Publishing" description="DETAILFINISH" /> You can add as many parameters as you like in here like this <params addpath="/administrator/components/com_content/elements"> <param name="created_by" type="author" default="" label="Author" description="DETAILAUTHOR" /> <param name="created_by_alias" type="text" size="20" default="" label="Author Alias" description="DETAILAUTHORALIAS" /> <param name="access" type="list" size="20" default="0" label="Access Level" description="DETAILACCESS"> <option value="0">Public</option> <option value="1">Registered</option> <option value="2">Special</option> </param> <param name="created" type="calendar" default="" label="Created Date" description="DETAILCREATED" /> <param name="publish_up" type="calendar" default="" label="Start Publishing" description="DETAILSTART" /> <param name="publish_down" type="calendar" default="" label="Finish Publishing" description="DETAILFINISH" /> <param name="is_featured" type="radio" default="" label="Featured Article" description="ISFEATURED"> <option value="0">No</option> <option value="1">Yes</option> </param> </params> If you now go to the admin section and edit an article you will see your parameter "Featured Article" listed on the right just under "Finish Publishing" At this point however it will not save yet. So to have the field save in the database there is four steps. First create a column in your jos_content database called "is_featured" and make sure the column type is appropriate so the values you supply in the article.xml file can be saved into that column. In this case I made the column type tinyint(1) as it really only takes values 0 and 1 Next you need to let joomla know that there is a new column in the database called "is_featured" Edit the file: libraries/joomla/database/table/content On line 66 directly after publish_down add your column "is_featured" like this: var $checked_out_time = 0; /** @var datetime */ var $publish_up = null; /** @var datetime */ var $publish_down = null; var $is_featured = null; /** @var string */ var $images = null; Now we need to update the code to load and save the variable. Edit administrator/components/com_content/controller.php on line 442 just after the publish_down is set, set your "is_featured" to load like this: $form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S')); $form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S')); if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $db->getNullDate()) { $form->set('publish_down', JText::_('Never')); } else { $form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S')); } $form->set('is_featured',$row->is_featured); // Advanced Group $form->loadINI($row->attribs); In the same file on line 1176 add your "is_featured" column so it will be saved. $row->checked_out_time = $item->checked_out_time; $row->publish_up = $item->publish_up; $row->publish_down = $item->publish_down; $row->is_featured = $item->is_featured; $row->images = $item->images; $row->attribs = $item->attribs; That is it. Hope this helps! By PHPin24 @ 2010-10-26 10:45:34
|
