1

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);
} 
} 
1

Just wanted to note that the same question was asked by @ajhuddy in Joomla! General Development maillist and it has an answer.

**** SOLVED ****

(Thanks Hannes for leading me to the answer)

It seems to be key in the onContentPrepareForm part of the plugin to only make a change to the form if $form->getName() evaluates to the form you are wanting to alter.

  • Yes that was me I should have updated this question – Aaron Hudon Feb 27 '15 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.