I have written a simple plugin to include custom content against Joomla articles. Here's the code:
defined ( '_JEXEC' ) or die ( 'Restricted access' );
class plgContentHomegrid 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('homegrid', false);
}
return true;
}
return true;
}
}
This works fine, the additional fields are displayed as a separate tab in admin, data saves correctly and everything's perfect. So far so good...however, I only want to display the additional tab on the home page. So, I amended the code so the additional form is only displayed for the home page:
if( $data->featured == 1 ){
$form->loadFile('homegrid', false);
}
The form now only displays on the home page admin screen as needed BUT the data is not saved.
This is partially explained by this issue, but I'm not clear how I can amend the code so that the form is conditionally displayed AND saved.