I am looking to add parameters to the edit-view of my component's menu editor on the fly instead of statically defining them as you normally would (as described : https://docs.joomla.org/J3.x:Developing_a_MVC_Component/Adding_a_variable_request_in_the_menu_type ).
I have created a plugin and implemented onContentPrepareForm. Within the plugin I construct xml for fields with the name "params" so that this data will be stored in the [params] column for the menu.
The parameters are shown just fine on the form, however the data is not saved. I have traced this through the bowels of the JForm joomla code and it turns out the JForm framework is discarding all of the custom fields that have been added dynamically.
* Specifically (and this is where I need help) * JModelForm::validate() calls JForm::validate() calls JForm::findFieldsByGroup(). This last call eliminates my custom fields. If I comment out the first call to validate(), the data for my custom fields is stored.
Here's a sample of my plugin showing how I add the XML on the fly.
public function onContentPrepareForm( $form, $data)
{
$option = JFactory::getApplication()->input->get('option');
$view = JFactory::getApplication()->input->get('view');
$modifyForm = false;
// check if this is a menu item for my component
if($option == 'com_menus' && $view == 'item' && array_key_exists('component_id', $data))
{
$myComponent = JComponentHelper::getComponent('com_mycomponent');
if($data['component_id'] == $myComponent->id)
{
$modifyForm = true;
}
}
if($modifyForm)
{
$testXml = '<fields name="params">
<fieldset name="basic" label="FIELDSET-LABEL">
<field name="test-field" type="list" label="test-field-label" description="test-field-description">
<option value="">Default</option>
<option value="0">Zero</option>
<option value="1">One</option>
</field>
</fieldset>
</fields>';
$xmlElement = new SimpleXMLElement($testXml);
$form->setField($xmlElement);
}
}