7

In my system plugin , I am using following to load default options xml file for templates

function onContentPrepareForm($form, $data) {

    if (!($form instanceof JForm)){

    $this->_subject->setError('JERROR_NOT_A_FORM');
    }


    // Template defaults
    if ($form->getName() == 'com_templates.style') {
        JForm::addFormPath('pathtofolder');
        $form->loadFile('xmlfile', false, false , true);
    }
}

works fine

now in templateDetails.xml by default I will have params fields group empty

...
    <config>
        <fields name="params">

        </fields>
    </config>
...

also works fine and it display the default params from my xml file.

Now I want to give users an option to override the existing default param by simply adding it inside the templateDetails.xml.

example protostar default I changed templateBackgroundColor value from F4F6F7 to FF6600

<config>
    <fields name="params">
        <fieldset name="advanced">
        <field name="templateBackgroundColor" class="" type="color" default="#FF6600"
                label="TPL_PROTOSTAR_BACKGROUND_COLOR_LABEL"
                description="TPL_PROTOSTAR_BACKGROUND_COLOR_DESC" />
        </fieldset>
    </fields>
</config>

this also works , but the field is in wrong position now it is located as the first field on top and it was second.

According to the loadFile() and load() method it should override the field in its exact place.

https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/form.php#L851 https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/form.php#L727

What am I missing here? Did the load fire to soon before the template xml ?

Any help is appreciated.

2
  • I will take a guess, perhaps the load order. If the protostar loads second, it replaced the 0 index of the main xml. So reversing the order based on what should override what might help. Though I do have some trouble understanding the question, any chance for clarification? May 7, 2014 at 0:10
  • @JordanRamstad, apparently the params order here has something to do what and who is displayed/overwritten, $form->loadFile('xmlfile', false, false , true); , thus I asked how to set it up properly.
    – Dan
    May 7, 2014 at 12:04

1 Answer 1

2

No, it doesn't override the field in place, it overrides the node in place.

In your case you are merging node:fieldset->name:advanced node:field->name:templateBackgroundColor...

into node:fieldset->name:advanced node:field->name:templateColor... node:field->name:templateBackgroundColor... ....

The order of your fieldset node is: templateBackgroundColor The order of the original fieldset node is: templateColor, templateBackgroundColor

Confusing because from the wording of the Joomla docs, it implies that it is merging the fields "in place", but it is merging the xml "in place"

The best way to maintain ordering is to add to your file

Alternatively, you can use a lot of the lower level form api to manipulate the XML. I don't recommend that because the form API changes from time to time to fix problems in documented functionality vs actual functionality

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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