I'm trying to add a single, simple field to each #__content item, and I've very carefully followed the tutorial at Adding Custom Fields to Core Components, substituting "content" for "contact". I now have an installable plugin that successfully includes the tab/field on the Admin Content Item editing form, and works wonderfully, except for that pesky "saving" feature.
The only reference to Saving is (again,content instead of contact) :
The additional fields are loaded from the file forms/contact.xml in the plugin directory. It's important that these fields are in a fields element with the name property set to "params". If you don't set this property name the fields will appear in the admin site but the values will not be saved.
The fact that this cautionary note exists, suggests to me that Joomla should know the fields are there, and the core code handles it, but since it's not saving, I'm wondering if there's another event I should be adding.
Here's the simple field I need - invisible to the user, but critical nonetheless, and nowhere near the need of a CCK to store it.
What is wrong/missing that is preventing the custom field from being saved?
Update: Hoping beyond hope that the custom field was stored in the database, I added a column to the #__content table with the same name and tried - no luck.
gdp.php
class plgContentGdp extends JPlugin {
protected $autoloadLanguage = true;
function onContentPrepareForm($form, $data) {
$app = JFactory::getApplication();
$option = $app->input->get('option');
switch($option) {
case 'com_content':
if ($app->isAdmin()) {
JForm::addFormPath(__DIR__ . '/forms');
$form->loadFile('content', false);
}
return true;
}
return true;
}
}
/forms/content.xml
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params" >
<fieldset name="params" >
<field
name="content_myfield"
type="text"
label="PLG_CONTENT_GDP_MYFIELD"
/>
</fieldset>
</fields>
</form>
Rendered HTML (without the label)
<div class="tab-pane active" id="attrib-params">
<div class="control-group ">
<div class="controls">
<input
type="text"
value=""
id="jform_params_content_myfield"
name="jform[params][content_myfield]"
class=""
aria-invalid="false"
>
</div>
</div>
</div>