I believe I have your solution, but do NOT hack the core. We felt forced to do that over the years, and we're still paying the price even today, missing updates, revisiting hacks everytime we do update, and general incompatibility with other components.
What we now do is this:
- New table
#__content_ext
with a key field that is identical to #__content
and a column for each custom field you want.
- New table
#__categories_ext
with a key field that is identical to #__categories
and a column for each custom field you may want.
- Add custom fields to com_content (we use and love Aixeena CCK which can add custom fields to content, categories, and menus).
At this point, you're leveraging all the code/logic in com_content
without a single core hack. However, your custom fields are all being stored in the params
and attribs
columns of the Joomla tables, which is not ideal for typical database use in other custom code you may need. This is where the "magic" comes in:
Write a simple content plugin using the below sample code to create/update the table extensions described above. This puts all your custom fields into custom tables which are available for whatever purpose you need them for in SQL.
public function onContentAfterSave($context=null, $article=null, $isNew=0) {
if($context == 'com_categories.category') {
$params = new JRegistry;
$params->loadString($article->params);
$myObj = $params->toObject();
// Use properties from $article and $myObj to create/update #__categories_ext
// Use $article->id as the primary key if #__categories_ext
// Your SQL goes here....
}elseif($context=='com_content.article'){
$attribs = new JRegistry;
$attribs->loadString($article->attribs);
$myObj = $attribs->toObject();
// Use properties from $article and $myObj to create/update #__content_ext
// Use $article->id as the primary key if #__content_ext
// Your SQL goes here....
}
}
Admittedly, the data is being stored twice - once as custom content, and again in your custom table, but bending that normalization rule MORE than pays for the work and grief that a core hack costs if you intend on keeping the site current to Joomla versions. You've also left things in such a state you can use all the com_content and other extensions that use com_content without any consequence of your hacks.